SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 01/11/2017, 10:03 AM   #1
Arbico
Big Clucker
 
Arbico's Avatar
 
Join Date: Jul 2017
Posts: 84
Reputation: 5
Default Variable Check

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?
__________________
Skype:Arbico
Anywhere, Anytime, i'm here to help.

Arbico is offline   Reply With Quote
Old 01/11/2017, 12:18 PM   #2
zMason
Little Clucker
 
zMason's Avatar
 
Join Date: Sep 2017
Posts: 36
Reputation: 10
Default Re: Variable Check

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.
zMason is offline   Reply With Quote
Old 01/11/2017, 12:57 PM   #3
CXdur
Big Clucker
 
CXdur's Avatar
 
Join Date: Jun 2014
Location: Norway
Posts: 57
Reputation: 6
Default Re: Variable Check

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.
CXdur is offline   Reply With Quote
Old 01/11/2017, 02:13 PM   #4
Arbico
Big Clucker
 
Arbico's Avatar
 
Join Date: Jul 2017
Posts: 84
Reputation: 5
Default Re: Variable Check

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)
__________________
Skype:Arbico
Anywhere, Anytime, i'm here to help.

Arbico is offline   Reply With Quote
Old 01/11/2017, 03:03 PM   #5
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,801
Reputation: 635
Default Re: Variable Check

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).

http://wiki.sa-mp.com/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.
NaS is offline   Reply With Quote
Old 01/11/2017, 04:24 PM   #6
OneDay
Huge Clucker
 
Join Date: Sep 2015
Posts: 294
Reputation: 139
Default Re: Variable Check

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?
OneDay is offline   Reply With Quote
Old 01/11/2017, 05:52 PM   #7
Arbico
Big Clucker
 
Arbico's Avatar
 
Join Date: Jul 2017
Posts: 84
Reputation: 5
Default Re: Variable Check

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.
__________________
Skype:Arbico
Anywhere, Anytime, i'm here to help.

Arbico is offline   Reply With Quote
Old 01/11/2017, 09:03 PM   #8
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,773
Reputation: 858
Default Re: Variable Check

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.
__________________

Follow me on Github: Donate on Paypal to show your support:

Gammix is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if a variable is set? godless_phoenix Scripting Help 2 05/09/2016 07:22 PM
check if a variable has a string THE_KNOWN Help Archive 0 21/02/2011 11:24 AM
how to check variable is maximum jame42 Help Archive 5 21/11/2010 07:22 AM
[plaese Help me]How to check the most of a variable? Tigerbeast11 Help Archive 18 22/12/2009 12:09 PM


All times are GMT. The time now is 12:28 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.