Array must be indexed
#1

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

Anyone please ?

Sorry for bump
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)