SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 27/05/2019, 07:29 AM   #1
StRaphael
Big Clucker
 
StRaphael's Avatar
 
Join Date: Nov 2016
Posts: 124
Reputation: 0
Default Can please someone explain this function? Thanks

Hello, can someone explain the role of single quotes(') in this function please?
PHP Code:
IsANumber(const inputtext[])
{
    for(new 
istrlen(inputtext); i++)
    {
        if(
inputtext[i] > '9' || inputtext[i] < '0') return 0;
    }
    return 
1;

What are single quotes used for in pawn scripting? And how does the check work here(I mean how can this function check if a string is a numeral or not and calculate if a letter is higher or lower than 9 or 0)?
Thank you
StRaphael is offline   Reply With Quote
Old 27/05/2019, 07:47 AM   #2
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 679
Reputation: 110
Default Re: Can please someone explain this function? Thanks

Text is Ascii characters. Number 0 is 48 in ascii and number 9 is 57 in ascii. You can do:
pawn Code:
if(inputtext[i] > 57 || inputtext[i] < 48) return 0;
But is it easier to remember those numbers? We use single quote to make it a literal character.

Character '9' converts to 57.
Character 'A' convers to 65.

Reference: http://www.asciitable.com/
Calisthenics is offline   Reply With Quote
Old 27/05/2019, 08:59 AM   #3
StRaphael
Big Clucker
 
StRaphael's Avatar
 
Join Date: Nov 2016
Posts: 124
Reputation: 0
Default Re: Can please someone explain this function? Thanks

Quote:
Originally Posted by Calisthenics View Post
Text is Ascii characters. Number 0 is 48 in ascii and number 9 is 57 in ascii. You can do:
pawn Code:
if(inputtext[i] > 57 || inputtext[i] < 48) return 0;
But is it easier to remember those numbers? We use single quote to make it a literal character.

Character '9' converts to 57.
Character 'A' convers to 65.

Reference: http://www.asciitable.com/
Alright, thank you, that's all what I needed!
+rep
StRaphael 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
Someone please explain me this? akib Scripting Help 3 12/05/2017 05:57 PM
Can you explain...? Fancy Server Support 3 28/08/2015 06:03 PM
Can someone explain how this function works? MR_MAN Scripting Help 4 11/06/2012 02:00 PM
How can i explain this function? Artie_Scorpion Scripting Help 6 02/01/2012 05:04 PM
Can somebody explain the function SetPlayerVirtualWorld Rensy Help Archive 1 18/03/2010 08:51 PM


All times are GMT. The time now is 11:44 PM.


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