SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/07/2019, 05:02 AM   #1
sonn51280
Big Clucker
 
sonn51280's Avatar
 
Join Date: Jun 2017
Location: Vietnamese
Posts: 71
Reputation: 0
Default [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array eleme

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++;
	}
}
sonn51280 is offline   Reply With Quote
Old 12/07/2019, 05:05 AM   #2
sonn51280
Big Clucker
 
sonn51280's Avatar
 
Join Date: Jun 2017
Location: Vietnamese
Posts: 71
Reputation: 0
Default Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e

[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.
sonn51280 is offline   Reply With Quote
Old 12/07/2019, 09:40 AM   #3
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 240
Reputation: 13
Default Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e

Increase size of GateInfo.
And you really have over 500 gates in your database? o.O
Plastikmensch is offline   Reply With Quote
Old 12/07/2019, 01:31 PM   #4
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Posts: 440
Reputation: 31
Default Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e

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
v1k1nG is offline   Reply With Quote
Old 12/07/2019, 03:16 PM   #5
d3Pedro
Huge Clucker
 
Join Date: Apr 2012
Location: Los Santos
Posts: 249
Reputation: 79
Default Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e

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 ++)
d3Pedro is offline   Reply With Quote
Old 13/07/2019, 01:08 PM   #6
sonn51280
Big Clucker
 
sonn51280's Avatar
 
Join Date: Jun 2017
Location: Vietnamese
Posts: 71
Reputation: 0
Default Re: [12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array e

thank you and thanks Verry Verry much
sonn51280 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[debug] Attempted to read/write array element at index 90 in array of size 90 HELP ME D: tomasfernandez Scripting Help 3 16/03/2017 05:26 AM
[debug] Run time error 4: "Array index out of bounds" skiplovebra Scripting Help 2 13/04/2016 03:53 PM
[debug] Run time error 4: "Array index out of bounds" lulo356 Scripting Help 15 16/01/2016 03:52 PM
[debug] Run time error 4: "Array index out of bounds" and many more errors :P ntmp Scripting Help 2 11/08/2014 02:10 PM
[debug] Run time error 4: "Array index out of bounds" [READ FOR MORE INFO] Trynda Scripting Help 3 15/05/2014 10:28 AM


All times are GMT. The time now is 10:29 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.