SA-MP Forums Archive
ARRAY INDEX - 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 INDEX (/showthread.php?tid=456701)



ARRAY INDEX - DJ_Shocker - 07.08.2013

Код:
[19:16:48] [debug] Run time error 4: "Array index out of bounds"
[19:16:48] [debug] Accessing element at index 65535 past array upper bound 499
[19:16:48] [debug] AMX backtrace:
[19:16:48] [debug] #0 000889ec in public OnPlayerStateChange (playerid=0, newstate=1, oldstate=8) at CSRPtest.pwn:13250
pawn Код:
new spectator = GettingSpectated[playerid];
        if(!IsPlayerConnected(spectator))
        {
            GettingSpectated[playerid] = -1;
            Spectate[spectator] = -1;  //13250
        }



Re: ARRAY INDEX - Red_Dragon. - 07.08.2013

Here you're getting the spectated which I believe can return as 999, and later you're accessing PlayerInfo[spectator][pAdmin] without checking if it equals 999, there's probably more of this happening too but that's one instance of it and I'm not going to go over all your script.

A quick note for future proofing, I would set the invalid to -1 because in case your server slots increase to 1000 and the server fills up then you'll be running into problems, however player slots won't ever start from -1 so you wouldn't run into any problems in the future.
Also you could use a define instead of hardcoding and that way you wouldn't have to change all your 999's
pawn Код:
new spectator = GettingSpectated[playerid];
        if(!IsPlayerConnected(spectator))
        {
            GettingSpectated[playerid] = 999;
            Spectate[spectator] = 999;
        }

        if(newstate == PLAYER_STATE_DRIVER && PlayerInfo[spectator][pAdmin] >= 2 || newstate == PLAYER_STATE_PASSENGER && PlayerInfo[spectator][pAdmin] >= 2)
        {
This solution was posted by cessil in one of my old threads which I had the same problem as you.