Run time error 4: "Array index out of bounds" at crashdedect.
#1

First sorry for my bad english and bad title name( maybye ), but I have problem.
I have that error not in compiler but in concole( when playing ):
Код:
[19:37:54] [debug] AMX backtrace:
[19:37:54] [debug] #0 0000aa98 in public OnPlayerUpdate (playerid=0) at C:\Users\Vartotojas\Desktop\SA-MP\gamemodes\rfe.pwn:682
[19:37:54] [debug] Run time error 4: "Array index out of bounds"
[19:37:54] [debug]  Accessing element at index 11 past array upper bound 0
I creating speedometer and i upload some functions, what can help:

Код:
new Float:SpeedOfVehicles[ ][ ] =  {
	{160.0},//Landstaker
	{160.0},
	{200.0},
	{120.0},
	{150.0},
	{165.0},
	{110.0},
	{170.0},//Firetruck
	{110.0},//Trashmaster
	{180.0},
	{160.0},
	{240.0},
	{160.0},
	{160.0},
	{140.0},
	{230.0},//Cheetah
	{155.0}
};//Ambulance
I don't upload all.

Код:
new bar = floatround( GetVehicleSpeed(GetPlayerVehicleID(playerid)) / SpeedOfVehicles[ vehar ][ model - 400 ] * 30,floatround_round);
That is 682 line.

P.S. Merry Christmas and Happy New Year!
Reply
#2

That's an odd one. It's like the size of the array is 1 and the valid index is 0 but it accessed the element at index 11.

You do have a 2D array that gets only float and you have only float points (the speed). Then your code is:
pawn Код:
SpeedOfVehicles[ vehar ][ model - 400 ]
vehar is the vehicleid? Well, it's pretty pointless. All you need is the modelid so you can subtract from 400 and get the speed on the single array.

pawn Код:
new Float: SpeedOfVehicles[212] = {
    160.0, // modelid: 400
    // ... {the rest of the speed values for each model},
    0.0 // modelid: 611
};
Then:
pawn Код:
new
    modelid = GetVehicleModel(GetPlayerVehicleID(playerid));

if (modelid) // valid modelid
{
    // ...
    new bar = floatround(GetVehicleSpeed(GetPlayerVehicleID(playerid)) / SpeedOfVehicles[modelid - 400] * 30, floatround_round);
    // ...
}
Reply
#3

Thanks a lot! Now everytime I can fix that
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)