Gamemode crash
#1

Код:
[09:39:16] [debug] Run time error 4: "Array index out of bounds"
[09:39:16] [debug]   Accessing element at index 999 past array upper bound 500
[09:39:16] [debug] Backtrace (most recent call first):
[09:39:16] [debug] #0  000603e0 in OnPlayerStateChange () from OGHRP.amx
This is what I get before it crashes

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate != 2) NOPTrigger[playerid] = 0;
    if(IsPlayerNPC(playerid))
	{
	    if(newstate == PLAYER_STATE_SPECTATING)
	    {
        	TogglePlayerSpectating(playerid, false);
		}
		return 1;
	}
	if(GettingSpectated[playerid] != 999)
	{
	    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)
	    {
	        TogglePlayerSpectating(spectator, true);
			new carid = GetPlayerVehicleID( playerid );
			PlayerSpectateVehicle( spectator, carid );
			SetPVarInt(spectator, "SpecState", newstate);
	    }
	    else if(newstate == PLAYER_STATE_ONFOOT && PlayerInfo[spectator][pAdmin] >= 2)
	    {
	        TogglePlayerSpectating(spectator, true);
		   	PlayerSpectatePlayer( spectator, playerid );
		   	SetPlayerInterior( spectator, GetPlayerInterior( playerid ) );
			SetPVarInt(spectator, "SpecState", newstate);
	    }
	}
Reply
#2

Check your array sizes
Reply
#3

I still can't seem to figure out the problem, I'm trying to learn from these errors.. but for now they're killing the learning part, lol.
Reply
#4

Your problem is the "spectator" var you are using as an index. When it is set to 999, you are using it as an index for an array that isn't that large.

EDIT: Print the value of "spectate" before you use it on an array and check if the array is large enough for it.
Reply
#5

Hey

Thank you for the answers, yet I am not completely sure how I am supposed to "Print the value of spectate before you use it on an array"

I'm a newbie to this, and I'm still in the learning process. So if you could simplify your answer, I'd be happy. Hope it's not too much trouble.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)