Stuck on variables.. again... Indexing arrays?
#1

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
Reply
#2

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
Reply
#3

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)