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=399629)



Array must be indexed - Mado - 15.12.2012

I have got this code in my script and it says the array must be indexed (target), while I think I did. What might be the issue?

pawn Код:
new target[26];
            target = ReturnUser("inputtext");
            if(target != INVALID_PLAYER_ID)



Re: Array must be indexed - Huxley - 15.12.2012

I think the index was supposed to be MAX_PLAYERS.


Re: Array must be indexed - C00K13M0N$73R - 15.12.2012

Remove [26] as target is a id.


Re: Array must be indexed - Mado - 15.12.2012

Can you explain that a little bit better?


Re: Array must be indexed - C00K13M0N$73R - 15.12.2012

pawn Код:
new target;
            target = ReturnUser("inputtext");
            if(target != INVALID_PLAYER_ID)
Target is a integer. Not a string. ReturnUser return's a ID, not a name.


Re: Array must be indexed - Konstantinos - 15.12.2012

Target gets the ID of a user. In your case, you're getting the user's name by inputtext.
pawn Код:
new
    target
;
target = ReturnUser(inputtext);
if(target != INVALID_PLAYER_ID)
If you use on inputtext " ", that means that you're searching for a player named inputtext!


Re: Array must be indexed - Mado - 15.12.2012

Quote:
Originally Posted by C00K13M0N$73R
Посмотреть сообщение
Remove [26] as target is a id.
Actually it is a name, since the player must insert a full name in the dialog.


-----

Alright I did this:
pawn Код:
new target = ReturnUser("inputtext");
And it compiles, but when I am ingame this part won't work:

pawn Код:
if(target != INVALID_PLAYER_ID)
            {
                //blabla
            }
            else
            {
                //blabla

            }
Ofcourse the //blabla contains code, but even if the name is a correct one it is recognized as an invalid one.


Re: Array must be indexed - C00K13M0N$73R - 15.12.2012

if(target != INVALID_PLAYER_ID)

This means if the target is NOT a valid playerid. Make sure your code isn't backwards.


Re: Array must be indexed - Konstantinos - 15.12.2012

If you read my post above, you'll understand that the name you insert into the dialog is not called to the ReturnUser, as you've got
pawn Код:
"inputtext"
and it searchs for a player named inputtext, not what you've inserted into the dialog.

Quote:
Originally Posted by C00K13M0N$73R
Посмотреть сообщение
if(target != INVALID_PLAYER_ID)

This means if the target is NOT a valid playerid. Make sure your code isn't backwards.
That means the opposite from what you said. If the target is not an invalid player, continue!


Re: Array must be indexed - ikey07 - 15.12.2012

You should use IsPlayerConnected(target ); instead of if(target != INVALID_PLAYER_ID) because if someone enter player id what isnt connected, but is valid, your script wont work