SA-MP Forums Archive
Array Must Be Indexed - 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: Array Must Be Indexed (/showthread.php?tid=87041)



Array Must Be Indexed - refshal - 17.07.2009

Okay, this is the first time ever I am asking about help. But, it's because I was sitting very very very long and thought about this, but didn't find any solution. So, well... Here's my code:

pawn Код:
new text;
text = strval(params);
if(text == "red")
And the error is:

Quote:
Originally Posted by Pawno
error 033: array must be indexed (variable "-unknown-")
And "unknown" is "red". What do I have to do?


Re: Array Must Be Indexed - Jefff - 17.07.2009

Because U r using integer and string?
Код:
text = strval(params);
text is integer
Код:
if(text == "red")
and integer == string?


Re: Array Must Be Indexed - M4S7ERMIND - 17.07.2009

I think this is what you need

Код:
if(strcmp(params,"red",true) == 0)



Re: Array Must Be Indexed - refshal - 17.07.2009

Quote:
Originally Posted by Μαστερμινδ
I think this is what you need

Код:
if(strcmp(params,"red",true) == 0)
I don't want to make a "/red" command...

Quote:
Originally Posted by Jefff
Because U r using integer and string?
Код:
text = strval(params);
text is integer
Код:
if(text == "red")
and integer == string?
Yeah, maybe... Got any solutions?


Re: Array Must Be Indexed - Jefff - 17.07.2009

Quote:
Originally Posted by еddy
Quote:
Originally Posted by Μαστερμινδ
I think this is what you need

Код:
if(strcmp(params,"red",true) == 0)
I don't want to make a "/red" command...
this is not a command its check
if(!strcmp(text,"red",true)) //if your "text" is "red" do something


Re: Array Must Be Indexed - refshal - 17.07.2009

Ok, Jefff, thanks for the notice.

And sorry Μαστερμινδ, it actually worked. Thank you guys.


Re: Array Must Be Indexed - M4S7ERMIND - 17.07.2009

Quote:
Originally Posted by еddy
Quote:
Originally Posted by Μαστερμινδ
I think this is what you need

Код:
if(strcmp(params,"red",true) == 0)
I don't want to make a "/red" command...
Heres an example

pawn Код:
dcmd_setcolor(playerid, params[]) {
  if(!strlen(params)) return SendClientMessage(playerid, WHITE, "Use: /setcolor [color]");
  if(strcmp(params,"red",true) == 0) return SetPlayerColor(playerid, COLOR_RED);
  else if(strcmp(params,"blue",true) == 0) return SetPlayerColor(playerid, COLOR_BLUE);
  else return SendClientMessage(playerid, WHITE, "Unknown color..");
}
EDIT: np