SA-MP Forums Archive
String in if() statements - 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 in if() statements (/showthread.php?tid=401075)



String in if() statements - Riddy - 21.12.2012

How can I add stirng in 'if' statements?

I am trying to check if a certain var contains 'None'...


Re: String in if() statements - Lapon - 21.12.2012

Can you please tell a bit more clearly actually what your wanting?


Re: String in if() statements - Lordzy - 21.12.2012

wiki.sa-mp.com/wiki/strcmp
Example:
pawn Код:
new Lname[MAX_PLAYER_NAME];
GetPlayerName(playerid, Lname, sizeof(Lname));
if(!strcmp(Lname, "None", true)) return SendClientMessageToAll(-1, "None");



Re: String in if() statements - Riddy - 21.12.2012

The thing is, am looking for something like this:

if(hInfo[h][hOwner] == "None")
{
CreateObject(blah blah);
}


Re: String in if() statements - ikey07 - 21.12.2012

use strfind function

if(!strfind(string,"None", true))


Re: String in if() statements - Riddy - 21.12.2012

Quote:
Originally Posted by ikey07
Посмотреть сообщение
use strfind function

if(!strfind(string,"None", true))
Ah never though of that, thanks ikey


Re: String in if() statements - wups - 21.12.2012

Quote:
Originally Posted by Riddy
Посмотреть сообщение
Ah never though of that, thanks ikey
No, for the reason you need it - use strcmp(like in the example above).


Re: String in if() statements - Riddy - 21.12.2012

Quote:
Originally Posted by wups
Посмотреть сообщение
No, for the reason you need it - use strcmp(like in the example above).
I dont see why I should use strcmp, considering am only looking for 'None' in the variables hInfo[h][hOwner]...

if(strfind(hInfo[h][hOwner], "None", true)), this looks for 'None' in the variables as for as I know...


Re: String in if() statements - AndreT - 21.12.2012

What the hell is the problem with you? If your property does not have an owner, make the string "*" by simply assigning the value (no format, no strcat, no whatsoever, just simply = to assign).
To check if the property is unowned, do if(hInfo[h][hOwner][0] == '*'). Simple and quick, voila.

And there's really nothing to justify using strfind instead of strcmp if you've designed the system yourself and are aware of the array contents


Re: String in if() statements - Riddy - 21.12.2012

Quote:
Originally Posted by AndreT
Посмотреть сообщение
What the hell is the problem with you? If your property does not have an owner, make the string "*" by simply assigning the value (no format, no strcat, no whatsoever, just simply = to assign).
To check if the property is unowned, do if(hInfo[h][hOwner][0] == '*'). Simple and quick, voila.

And there's really nothing to justify using strfind instead of strcmp if you've designed the system yourself and are aware of the array contents
The thing is, I never made the system, but I know whats the data suppose to be.. and am just looking if 'None' is in there and yes am wrong, I should be using strcmp not strfind.