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)
+--- Thread: Array must be indexed. (/showthread.php?tid=485134)



Array must be indexed. - Tayab - 03.01.2014

So I made a stock which is overall fine except for one error which keeps me from compiling my script.

Error:
Код:
C:\Users\iSoomro\Desktop\NameIt Server - MySQL\gamemodes\tm-mysql.pwn(3581) : error 033: array must be indexed (variable "pName")
Stock:
pawn Код:
stock GetOrgOfLeader(playerid)
{
    if(IsPlayerLeader(playerid))
    {
        for(new i = 0; i < MAX_ORGS; i++)
        {
            if(pName(playerid) == OrgInfo[i][oLeader])
            {
                return i;
            }
        }
    }
    return 0;
}
Occurrence Line (3581):
pawn Код:
if(pName(playerid) == OrgInfo[i][oLeader])
EDIT: And a pName stock
pawn Код:
stock pName(playerid)
{
    new PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,PlayerName,sizeof(PlayerName));
    return PlayerName;
}
Seeking a quick help.


Re: Array must be indexed. - HardRock - 03.01.2014

In 'If' you cant make 'if(string == string)' you only can 'if(number == number)'.


Re: Array must be indexed. - Emmet_ - 03.01.2014

You need to use strcmp.

pawn Код:
stock GetOrgOfLeader(playerid)
{
    if (IsPlayerLeader(playerid))
    {
        for (new i = 0; i < MAX_ORGS; i++)
        {
            if (!strcmp(pName(playerid), OrgInfo[i][oLeader]) && OrgInfo[i][oLeader][0] != '\0')
            {
                return i;
            }
        }
    }
    return 0;
}



Re: Array must be indexed. - Tayab - 03.01.2014

Oh shit! I am so stupid. I'll just use strcmp. Thanks anyway. +rep.