[debug] Run time error 4: "Array index out of bounds" [++REP]
#1

hello guys i have a problem

debug
pawn Код:
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at index 43 past array upper bound 42
[debug] AMX backtrace:
[debug] #0 00068408 in ?? (0x00000000) from MLRP.amx
[debug] #1 0006b31c in public MP_OPC (0x00000000) from MLRP.amx
[debug] #2 native CallLocalFunction () [00474110] from samp-server.exe
[debug] #3 00015c68 in ?? (0x00000000) from MLRP.amx
[debug] #4 0000c478 in public Itter_OnPlayerConnect (0x00000000) from MLRP.amx
[debug] #5 00007054 in public SSCANF_OnPlayerConnect (0x00000000) from MLRP.amx
[debug] #6 00000790 in public OnPlayerConnect (0x00000000) from MLRP.amx
pawn Код:
public OnPlayerConnect(playerid)
{
      RemoveBuildingsForPlayer(playerid);
      return 1;
}
pawn Код:
RemoveBuildingsForPlayer(playerid)
{
    // Remove 24/7 machines
        RemoveBuildingForPlayer(playerid, 1776, -33.8750, -186.7656, 1003.6328, 0.25);
    RemoveBuildingForPlayer(playerid, 1775, -32.4453, -186.6953, 1003.6328, 0.25);

    // Remove all other machines
    for(new i = 0; i < 44; i++)
    {
        RemoveBuildingForPlayer(playerid, 955, VMachines[i][0], VMachines[i][1], VMachines[i][2], 0.50);
        RemoveBuildingForPlayer(playerid, 956, VMachines[i][0], VMachines[i][1], VMachines[i][2], 0.50);
    }
    return 1;
}

pawn Код:
new Float:VMachines[43][3] = {
//Candy machines:
{2480.86,-1959.27,12.9609},
{1634.11,-2237.53,12.8906},
{2139.52,-1161.48,23.3594},
{2153.23,-1016.15,62.2344},
{-1350.12,493.859,10.5859},
{-2229.19,286.414,34.7031},
{1659.46,1722.86,10.2188},
{2647.7,1129.66,10.2188},
{2845.73,1295.05,10.7891},
{1398.84,2222.61,10.4219},
{-1455.12,2591.66,55.2344},
{-76.0312,1227.99,19.125},
{662.43,-552.164,15.7109},
{-253.742,2599.76,62.2422},
{2271.73,-76.4609,25.9609},

//Sprunk machines:
{1789.21,-1369.27,15.1641},
{1729.79,-1943.05,12.9453},
{2060.12,-1897.64,12.9297},
{1928.73,-1772.45,12.9453},
{2325.98,-1645.13,14.2109},
{2352.18,-1357.16,23.7734},
{1154.73,-1460.89,15.1562},
{-1350.12,492.289,10.5859},
{-2118.97,-423.648,34.7266},
{-2118.62,-422.414,34.7266},
{-2097.27,-398.336,34.7266},
{-2092.09,-490.055,34.7266},
{-2063.27,-490.055,34.7266},
{-2005.65,-490.055,34.7266},
{-2034.46,-490.055,34.7266},
{-2068.56,-398.336,34.7266},
{-2039.85,-398.336,34.7266},
{-2011.14,-398.336,34.7266},
{-1980.79,142.664,27.0703},
{2319.99,2532.85,10.2188},
{1520.15,1055.27,10.00},
{2503.14,1243.7,10.2188},
{2085.77,2071.36,10.4531},
{-862.828,1536.61,21.9844},
{-14.7031,1175.36,18.9531},
{-253.742,2597.95,62.2422},
{201.016,-107.617,0.898438},
{1277.84,372.516,18.9531}
};
plz help
thnx
Reply
#2

You can try it.
pawn Код:
for(new i = 0; i < sizeof(VMachines); i++)
Reply
#3

Quote:
Originally Posted by simo0000
Посмотреть сообщение
hello guys i have a problem

debug

Large code...
[/PAWN]

plz help
thnx
This is your problem:
Код:
RemoveBuildingsForPlayer(playerid)
{
	// Remove 24/7 machines
        RemoveBuildingForPlayer(playerid, 1776, -33.8750, -186.7656, 1003.6328, 0.25);
	RemoveBuildingForPlayer(playerid, 1775, -32.4453, -186.6953, 1003.6328, 0.25);

	// Remove all other machines
    for(new i = 0; i < 44; i++)
	{
		RemoveBuildingForPlayer(playerid, 955, VMachines[i][0], VMachines[i][1], VMachines[i][2], 0.50);
		RemoveBuildingForPlayer(playerid, 956, VMachines[i][0], VMachines[i][1], VMachines[i][2], 0.50);
	}
	return 1;
}
You defined "VMachines" as an array with the first dimension of 43 elements, yet that means that it holds element indices from 0-42 inclusively. You're trying to access the 43rd element, which is wrong and it spits out an error.
I suggest you write your for loop like this (that way, whenever you change its size it is adjusted when you compile):
Код:
for(new i = 0; i < sizeof(VMachines); i++)
Edit: zSuYaNw was faster, but I thought I should still post to understand why you got this error in the first place.
Reply
#4

thnx guys +rep for you both rep me back if you want

thnx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)