SA-MP Forums Archive
Run time error 4: "Array index out of bounds" - 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: Run time error 4: "Array index out of bounds" (/showthread.php?tid=531853)



Run time error 4: "Array index out of bounds" - Porgand - 15.08.2014

Код:
[03:13:21] [debug] Run time error 4: "Array index out of bounds"
[03:13:21] [debug]  Accessing element at negative index -1
[03:13:21] [debug] AMX backtrace:
[03:13:21] [debug] #0 001168f4 in public OnPlayerStateChange (0x00000003, 0x00000003, 0x00000001) from egsrp.amx
Код:
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
	{
	    new CarIDs = GetPlayerVehicleID(playerid), BuyCarID = GetBuyCarId(playerid);
		new CarModel = GetVehicleModel(CarIDs);
		if(CarInfo[BuyCarID][cRadio] == 1 || CarInfo[BuyCarID][cRadio] == 2)
		{
		    switch(CarRadioWorks[CarIDs])
		    {
		        case 0: StopAudioStreamForPlayer(playerid);
		        case 1: PlayAudioStreamForPlayer(playerid, "http://radiopage2.com");
		        case 2: PlayAudioStreamForPlayer(playerid, "http://radiopage3.com");
		        case 3: PlayAudioStreamForPlayer(playerid, "http://radiopage4.com");
		    }
		}
		switch(CarModel)
		{
			case 592,577,511,512,520,593,553,476,519,460,513,548,425,417,487,488,497,563,447,469: PlayerInfo[playerid][pWeapons][46] = true;
			case 457: PlayerInfo[playerid][pWeapons][2] = true;
			case 596,597,598,599: PlayerInfo[playerid][pWeapons][25] = true;
		}
	}



Re: Run time error 4: "Array index out of bounds" - youssefehab500 - 15.08.2014

Quote:
Originally Posted by Porgand
Посмотреть сообщение
Код:
[03:13:21] [debug] Run time error 4: "Array index out of bounds"
[03:13:21] [debug]  Accessing element at negative index -1
[03:13:21] [debug] AMX backtrace:
[03:13:21] [debug] #0 001168f4 in public OnPlayerStateChange (0x00000003, 0x00000003, 0x00000001) from egsrp.amx
Код:
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
	{
	    new CarIDs = GetPlayerVehicleID(playerid), BuyCarID = GetBuyCarId(playerid);
		new CarModel = GetVehicleModel(CarIDs);
		if(CarInfo[BuyCarID][cRadio] == 1 || CarInfo[BuyCarID][cRadio] == 2)
		{
		    switch(CarRadioWorks[CarIDs])
		    {
		        case 0: StopAudioStreamForPlayer(playerid);
		        case 1: PlayAudioStreamForPlayer(playerid, "http://radiopage2.com");
		        case 2: PlayAudioStreamForPlayer(playerid, "http://radiopage3.com");
		        case 3: PlayAudioStreamForPlayer(playerid, "http://radiopage4.com");
		    }
		}
		switch(CarModel)
		{
			case 592,577,511,512,520,593,553,476,519,460,513,548,425,417,487,488,497,563,447,469: PlayerInfo[playerid][pWeapons][46] = true;
			case 457: PlayerInfo[playerid][pWeapons][2] = true;
			case 596,597,598,599: PlayerInfo[playerid][pWeapons][25] = true;
		}
	}
hmmm try to check oldstate before the new state might help


Re: Run time error 4: "Array index out of bounds" - Porgand - 15.08.2014

When i leave the vehicle then the server log don't show nothing. But when i enter the car and close the door then will come that errors. Passenger as well as driver.


Re: Run time error 4: "Array index out of bounds" - ThePhenix - 15.08.2014

Why don't you use "print" to know the exact point that the console shows that message?


Re: Run time error 4: "Array index out of bounds" - Porgand - 17.08.2014

What u mean? Make some example.


Re: Run time error 4: "Array index out of bounds" - LivingLikeYouDo - 17.08.2014

This:
pawn Код:
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
|| means that there is an or statement in the script, so the seconds newstate must be removed.

pawn Код:
if((newstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER) && !(oldstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER))



Re: Run time error 4: "Array index out of bounds" - Porgand - 22.08.2014

Yeah, now it's ok. Ty all.