SA-MP Forums Archive
Stuck on variables.. again... Indexing arrays? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Stuck on variables.. again... Indexing arrays? (/showthread.php?tid=165960)



Stuck on variables.. again... Indexing arrays? - plutoniumman - 06.08.2010

Hi all

I'm trying to write a script to check whether or not the player's name is earl when they send the '/admin' command.
Just for simplicity & evaluation purposes..

Here it is:
http://pastebin.com/KaaUebz4

My problem is when I go to compile, it returns an error stating that the variable 'string' must be indexed.
I don't know how to index it... (I'm really starting to regret learning a language so loose on variables as my first >.<)
Nor do I know why it needs to be indexed if it's been formatted to a single line by the format function.

Any help or tips/hints are greatly appreciated TIA


Re: Stuck on variables.. again... Indexing arrays? - JaTochNietDan - 06.08.2010

The Pawn language doesn't support the comparing of two strings directly like

pawn Код:
if (string == "Earl")
You need to use the "strcmp" function to compare strings, like so

pawn Код:
if(!strcmp(string,"Earl",true))
I'm sure you can figure out most of it, but the last parameter is a bool for if you want to ignore case or not when comparing. Also there is an optional parameter at the end of strcmp where you can put the length of the string for a different reason, it is not needed in this situation.

https://sampwiki.blast.hk/wiki/Strcmp


Re: Stuck on variables.. again... Indexing arrays? - plutoniumman - 06.08.2010

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
The Pawn language doesn't support the comparing of two strings directly like

pawn Код:
if (string == "Earl")
You need to use the "strcmp" function to compare strings, like so

pawn Код:
if(!strcmp(string,"Earl",true))
I'm sure you can figure out most of it, but the last parameter is a bool for if you want to ignore case or not when comparing. Also there is an optional parameter at the end of strcmp where you can put the length of the string for a different reason, it is not needed in this situation.

https://sampwiki.blast.hk/wiki/Strcmp
Awesome that did it perfectly Thanks a ton and thanks too for such a quick reply