SA-MP Forums Archive
[12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array eleme - 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: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array eleme (/showthread.php?tid=667894)



[12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array eleme - sonn51280 - 12.07.2019

help me how to fix ?

Code:
stock LoadGates()
{
	printf("[LoadGates] Dang tai du lieu tu database...");
	mysql_function_query(MainPipeline, "SELECT * FROM `gates`", true, "OnLoadGates", "");
}

forward OnLoadGates();
public OnLoadGates()
{
	new i, rows, fields, tmp[128];
	cache_get_data(rows, fields, MainPipeline);
	while(i < rows)
	{
		cache_get_field_content(i, "HID", tmp, MainPipeline);  GateInfo[i][gHID] = strval(tmp);
		cache_get_field_content(i, "Speed", tmp, MainPipeline); GateInfo[i][gSpeed] = floatstr(tmp);
		cache_get_field_content(i, "Range", tmp, MainPipeline); GateInfo[i][gRange] = floatstr(tmp);
		cache_get_field_content(i, "Model", tmp, MainPipeline); GateInfo[i][gModel] = strval(tmp);
		cache_get_field_content(i, "VW", tmp, MainPipeline); GateInfo[i][gVW] = strval(tmp);
		cache_get_field_content(i, "Int", tmp, MainPipeline); GateInfo[i][gInt] = strval(tmp);
		cache_get_field_content(i, "Pass", GateInfo[i][gPass], MainPipeline, 24);
		cache_get_field_content(i, "PosX", tmp, MainPipeline); GateInfo[i][gPosX] = floatstr(tmp);
		cache_get_field_content(i, "PosY", tmp, MainPipeline); GateInfo[i][gPosY] = floatstr(tmp);
		cache_get_field_content(i, "PosZ", tmp, MainPipeline); GateInfo[i][gPosZ] = floatstr(tmp);
		cache_get_field_content(i, "RotX", tmp, MainPipeline); GateInfo[i][gRotX] = floatstr(tmp);
		cache_get_field_content(i, "RotY", tmp, MainPipeline); GateInfo[i][gRotY] = floatstr(tmp);
		cache_get_field_content(i, "RotZ", tmp, MainPipeline); GateInfo[i][gRotZ] = floatstr(tmp);
		cache_get_field_content(i, "PosXM", tmp, MainPipeline); GateInfo[i][gPosXM] = floatstr(tmp);
		cache_get_field_content(i, "PosYM", tmp, MainPipeline); GateInfo[i][gPosYM] = floatstr(tmp);
		cache_get_field_content(i, "PosZM", tmp, MainPipeline); GateInfo[i][gPosZM] = floatstr(tmp);
		cache_get_field_content(i, "RotXM", tmp, MainPipeline); GateInfo[i][gRotXM] = floatstr(tmp);
		cache_get_field_content(i, "RotYM", tmp, MainPipeline); GateInfo[i][gRotYM] = floatstr(tmp);
		cache_get_field_content(i, "RotZM", tmp, MainPipeline); GateInfo[i][gRotZM] = floatstr(tmp);
		cache_get_field_content(i, "Allegiance", tmp, MainPipeline); GateInfo[i][gAllegiance] = strval(tmp);
		cache_get_field_content(i, "GroupType", tmp, MainPipeline); GateInfo[i][gGroupType] = strval(tmp);
		cache_get_field_content(i, "GroupID", tmp, MainPipeline); GateInfo[i][gGroupID] = strval(tmp);
		cache_get_field_content(i, "FamilyID", tmp, MainPipeline); GateInfo[i][gFamilyID] = strval(tmp);
		cache_get_field_content(i, "RenderHQ", tmp, MainPipeline); GateInfo[i][gRenderHQ] = strval(tmp);
		cache_get_field_content(i, "Timer", tmp, MainPipeline); GateInfo[i][gTimer] = strval(tmp);
		cache_get_field_content(i, "Automate", tmp, MainPipeline); GateInfo[i][gAutomate] = strval(tmp);
		cache_get_field_content(i, "Locked", tmp, MainPipeline); GateInfo[i][gLocked] = strval(tmp);
		CreateGate(i);
		i++;
	}
}



Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e - sonn51280 - 12.07.2019

[12:03:40] [debug] Run time error 4: "Array index out of bounds"
[12:03:40] [debug] Attempted to read/write array element at index 500 in array of size 500
[12:03:40] [debug] AMX backtrace:
[12:03:40] [debug] #0 0034aa10 in public OnLoadGates () in sf-pro.amx
[12:03:40] [Family Points] 8 family points has been loaded.


Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e - Plastikmensch - 12.07.2019

Increase size of GateInfo.
And you really have over 500 gates in your database? o.O


Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e - v1k1nG - 12.07.2019

PHP Code:
[12:03:40] [debugAttempted to read/write array element at index 500 in array of size 500 
This means you have declared a variable which has 500 cells starting from 0 to 499.
You are trying to read/write at pos 500, thus out of bounds.

Numbers start from 0!

PHP Code:
new array[3]; 
means that correct indexes are

PHP Code:
array[0], array[1] and array[2], and not array[3



Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e - d3Pedro - 12.07.2019

You are attempting to read more than the defined value.
This should fix it or else just increase the defined value or delete some rows in the table.
pawn Code:
while(i < rows && i < MAX_GATES; i ++)



Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e - sonn51280 - 13.07.2019

thank you and thanks Verry Verry much