[debug] Run time error 4: "Array index out of bounds"
#2

You have to check if killerid is INVALID_PLAYER_ID before you use it on an array as an index.

INVALID_PLAYER_ID equals 65536 (0xFFFF).

This is what your really doing if killerid is invalid. (example)
pawn Код:
new array[ MAX_PLAYERS ];

array[ 65536 ] = something;//indexed oob
For example OnPlayerDeath should be similar to:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if( killerid != INVALID_PLAYER_ID )
    {
        ++kills[ killerid ];//killerid is ok it's not INVALID_PLAYER_ID
        ++deaths[ playerid ];
    }
    else
    {
        //dont use killerid as index here it's INVALID_PLAYER_ID
        ++deaths[ playerid ];
    }
    return 1;
}
Reply


Messages In This Thread
[debug] Run time error 4: "Array index out of bounds" - by nGen.SoNNy - 03.06.2012, 14:13
Re: [debug] Run time error 4: "Array index out of bounds" - by iggy1 - 03.06.2012, 14:19
Re: [debug] Run time error 4: "Array index out of bounds" - by nGen.SoNNy - 03.06.2012, 14:43
Re: [debug] Run time error 4: "Array index out of bounds" - by TheKingFTW15 - 06.03.2019, 16:16

Forum Jump:


Users browsing this thread: 1 Guest(s)