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=91537)
Array must be indexed -
Takumi.WS - 15.08.2009
the code :
Код:
if(strcmp(cmd, "/giveitem", true) == 0) // Kicks the player from the server
{
new reason[128];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, ORANGE, "USAGE: /giveitem [playername/id] [item]");
SendClientMessage(playerid, ORANGE, "FUNCTION: Will give an item to another player.");
return 1;
}
new giveplayerid = ReturnUser(tmp);
if(giveplayerid != INVALID_PLAYER_ID)
{
GetPlayerName(giveplayerid, giveplayername, sizeof(giveplayername));
GetPlayerName(playerid, sendername, sizeof(sendername));
reason = bigstrtok(cmdtext, idx);
if(!strlen(reason)) return SendClientMessage(playerid, ORANGE, "USAGE: /giveitem [playername/id] [item]");
if(reason == "Weapon licence")
{
AddItemToPlayerInventory(giveplayerid, 10, 1, "Weapon licence");
}
}
else if(giveplayerid == INVALID_PLAYER_ID)
{
format(string, sizeof(string), "%d is not an active player.", giveplayerid);
SendClientMessage(playerid, RED, string);
}
return 1;
}
the error :
C:\Documents and Settings\Azizo\Bureau\Los Santos Stories Role Play\gamemodes\rpg.pwn(4269) : error 033: array must be indexed (variable "reason")
the line 4269 is :
if(reason == "Weapon licence")
Thanks for your help =)
Re: Array must be indexed -
Takumi.WS - 15.08.2009
Anyone please ?
Sorry for bump
Re: Array must be indexed -
[BDC]Scarface - 15.08.2009
You must use the strcmp (String Compare) function.
Reason: A string is an array that contains characters. Eg. if your string said "Yes" it is stored like this... reason[0] = "Y", reason[1] = "e", reason[2] = "s" (then the last two chars are /0, to identify the end of a string). If you were to make this work the current way, you could only check one character at a time...
Eg of strcmp...
Код:
if(strcmp(reason, "Weapon Licence", true) == 0) // Returns 0 if string match
{
// Insert Funky Ass Code Here
}
Simple.