SA-MP Forums Archive
String and number compare. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: String and number compare. (/showthread.php?tid=373368)



String and number compare. - budelis - 30.08.2012

Hi. How to compare String and number? i have variable like this:

Code:
new NUMBER;
How to check if player text is same like this variable? I mean OnPlayerText.

I try:

Code:
if(!strcmp(text,NUMBER,true))
{
But i get errors.


Re: String and number compare. - Emmet_ - 30.08.2012

Try this:

pawn Code:
new szVal[12];
valstr(szVal, NUMBER);
if(!strcmp(text, szVal, true))
{
    ...
}



Re: String and number compare. - leonardo1434 - 30.08.2012

pawn Code:
new a[20],b;
if(strval(a) == b)
{
}



Re: String and number compare. - budelis - 30.08.2012

Thanks. Now why i get crashed when i do this:

Top in my gamemode:

Code:
new REACTIONTEST = 0;
Code:
new randomnumber1 = random( 100 );
new randomnumber2 = random( 100 );

REACTIONTEST = randomnumber1+randomnumber2;



Re: String and number compare. - leonardo1434 - 30.08.2012

it must be something else. this doesn't crash.
pawn Code:
public OnFilterScriptInit()
{
   new REACTIONTEST,randomnumber1 = random( 100 ),randomnumber2 = random( 100 );
   REACTIONTEST = randomnumber1+randomnumber2;
   printf(#%d, REACTIONTEST);
}



Re: String and number compare. - budelis - 30.08.2012

It's not crash, it's like i can't write any command. And it not always: here when it's bad:

Code:
0+17
When is 0 then it happin. Maybe 0 i can't use?