Array must be indexed
#1

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

I think the index was supposed to be MAX_PLAYERS.
Reply
#3

Remove [26] as target is a id.
Reply
#4

Can you explain that a little bit better?
Reply
#5

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

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!
Reply
#7

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

if(target != INVALID_PLAYER_ID)

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

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!
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)