Variable Check
#1

Wassap?
I wanna know how to check a variable if it's an integer or string etc.....
I need it because i'm making a new include and i really need help....
Anybody here got any idea?
Reply
#2

I'm not sure if there is an operator like that for pawno, I know that javascript and some other programming languages have an operator called 'typeof', it returns the variable type. I can't find anything on pawno about it.
Reply
#3

Quote:
Originally Posted by Arbico
View Post
Wassap?
I wanna know how to check a variable if it's an integer or string etc.....
I need it because i'm making a new include and i really need help....
Anybody here got any idea?
In what context do you need to check this? It could make it easier for us to help you.
Reply
#4

Quote:
Originally Posted by CXdur
View Post
In what context do you need to check this? It could make it easier for us to help you.
In an include called sampdb which stands for samp database, its a .sampdb editor(Never done before thats why im making it)
Reply
#5

You asked how you can check if a variable is a string or integer, but that doesn't really make sense because a string is an integer array! So your question must be a) How to get the tag of a variable (array or not), and b) How to determine if a variable is an array.

To determine the tag of a variable you can use tagof() which is a compiler function (like sizeof).

https://sampwiki.blast.hk/wiki/Keywords:Operators#tagof

You could use sizeof() to check whether or not a variable potentially is an Array. But it's only useful if the variable you are checking is existing by name (at that point you already know if it's an array or not..).

However these may be completely useless depending on what you are trying to do, so please be a bit more specific.
Reply
#6

Quote:
Originally Posted by Arbico
View Post
In an include called sampdb which stands for samp database, its a .sampdb editor(Never done before thats why im making it)
If you want to edit samp database, use sqlite. Or you want smth like sqliti?
Reply
#7

Quote:
Originally Posted by OneDay
View Post
If you want to edit samp database, use sqlite. Or you want smth like sqliti?
No bro, you got me wrong. Sqlite needs SQL knowledge, dini does not, but it cant save big info in one file, sampdb will combine both of them, store info in one file, without a need to learn any new language.
Reply
#8

You could add custom tags to variables while declaring, that's one way.

Here is what i mean:
PHP Code:
new Integer:myInt;
new 
String:myString[256];
new 
Float:myFloat// float already has it's tag
stock function({IntegerFloatString}:paramtag tagof param) {
    if (
tag == tagof(Integer:)) {
        
// its an integer
    
}
    else if (
tag == tagof(String:)) {
        
// its a string
    
}
    else if (
tag == tagof(Float:)) {
        
// its a float
    
}

There's another way of reading the variable as a string and then do a character check to determine its type.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)