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



[debug] Run time error 4: "Array index out of bounds" - BrainDamaged - 02.12.2017

Hi guys! Can somebody help me to detect the problem from this script? REP++



Код:
[19:10:06] [debug] Run time error 4: "Array index out of bounds"
[19:10:06] [debug]  Accessing element at negative index -399
[19:10:06] [debug] AMX backtrace:
[19:10:06] [debug] #0 0026ecbc in public cmd_myvehicles (playerid=0, params[]=@0021506c "") at C:\Users\HP\Desktop\LV-MP\pawno\include\cnr/command.inc:678
[19:10:06] [debug] #1 native CallLocalFunction () from samp-server.exe
[19:10:06] [debug] #2 0004c14c in public OnPlayerCommandText (playerid=0, cmdtext[]=@0021503c "/myvehicles") at C:\Users\HP\Desktop\LV-MP\pawno\include\required/zcmd.inc:102
[19:10:15] [pause] Veoper is now AFK.
myvehicle Command Code;
Код:
COMMAND:myvehicles(playerid, params[])
{
	new bool:found = false, msg[256];
	for(new i = 0; i < MAX_VEH; i++)
	{
		if(!Vehicles[i][vehStatus]) continue;
		
		if(Vehicles[i][vehOwner] == Player[playerid][pID])
		{
			found = true;
			format(msg, sizeof(msg), "%s%s ID : "CHAT_YELLOW"%d"CHAT_WHITE"\n", msg, vehicleNames[Vehicles[i][vehModel] - 400], Vehicles[i][vehID]);
		}
	}
	if(found)
	{
		if(Player[playerid][english])
			ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_LIST, "My Vehicles", msg, "Choose", "Cancel");
		else
			ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_LIST, "Mobil Saya", msg, "Pilih", "Batal");
	}
	else
	{
		if(Player[playerid][english])
			Server(playerid, "You didn't have any vehicles.");
		else
			Server(playerid, "Kamu tidak memiliki kendaraan.");
	}
	return 1;
}



Re: [debug] Run time error 4: "Array index out of bounds" - raydx - 02.12.2017

Too hard without error line.
Compile with -d3 flag and post your error again.


Re: [debug] Run time error 4: "Array index out of bounds" - BrainDamaged - 02.12.2017


Compile with gm but nothing error/warning message,
I get the error that I mentioned when I was using this command. (/myvehicles)
--------------------------------------------------------------------------------------------
sampserver.exe;

Код:
[debug] Run time error 4: "Array index out of bounds"
[debug] Accessing element at negative index -399
[debug] AMX backtrace:
[debug] #0 001ebdec in public cmd_myvehicles (0, 2167060) from CCNR.amx
[debug] #1 native CallLocalFunction () from samp-server.exe
[debug] #2 0003f0cc in public OnPlayerCommandText (0, 2167012) from CCNR.amx



Re: [debug] Run time error 4: "Array index out of bounds" - Konstantinos - 02.12.2017

You haven't compiled with debug info (-d3 flag) correctly. Follow this step by step (https://github.com/Zeex/samp-plugin-...ith-debug-info) and try again.

About the problem now, you have posted the wrong code. The problem is in /myvehicles command.


Re: [debug] Run time error 4: "Array index out of bounds" - BrainDamaged - 02.12.2017

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You haven't compiled with debug info (-d3 flag) correctly. Follow this step by step (https://github.com/Zeex/samp-plugin-...ith-debug-info) and try again.

About the problem now, you have posted the wrong code. The problem is in /myvehicles command.

I apologize, sir, my english is not good,I hope this time I can do the right thing;

Код:
[19:10:06] [debug] Run time error 4: "Array index out of bounds"
[19:10:06] [debug]  Accessing element at negative index -399
[19:10:06] [debug] AMX backtrace:
[19:10:06] [debug] #0 0026ecbc in public cmd_myvehicles (playerid=0, params[]=@0021506c "") at C:\Users\HP\Desktop\LV-MP\pawno\include\cnr/command.inc:678
[19:10:06] [debug] #1 native CallLocalFunction () from samp-server.exe
[19:10:06] [debug] #2 0004c14c in public OnPlayerCommandText (playerid=0, cmdtext[]=@0021503c "/myvehicles") at C:\Users\HP\Desktop\LV-MP\pawno\include\required/zcmd.inc:102
[19:10:15] [pause] Veoper is now AFK.
myvehicle Command Code;
Код:
COMMAND:myvehicles(playerid, params[])
{
	new bool:found = false, msg[256];
	for(new i = 0; i < MAX_VEH; i++)
	{
		if(!Vehicles[i][vehStatus]) continue;
		
		if(Vehicles[i][vehOwner] == Player[playerid][pID])
		{
			found = true;
			format(msg, sizeof(msg), "%s%s ID : "CHAT_YELLOW"%d"CHAT_WHITE"\n", msg, vehicleNames[Vehicles[i][vehModel] - 400], Vehicles[i][vehID]);
		}
	}
	if(found)
	{
		if(Player[playerid][english])
			ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_LIST, "My Vehicles", msg, "Choose", "Cancel");
		else
			ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_LIST, "Mobil Saya", msg, "Pilih", "Batal");
	}
	else
	{
		if(Player[playerid][english])
			Server(playerid, "You didn't have any vehicles.");
		else
			Server(playerid, "Kamu tidak memiliki kendaraan.");
	}
	return 1;
}



Re: [debug] Run time error 4: "Array index out of bounds" - raydx - 02.12.2017

Problem is here:

Код:
vehicleNames[Vehicles[i][vehModel] - 400]
Your vehModel - 400 is returning -399 and it is invalid for array.


Re: [debug] Run time error 4: "Array index out of bounds" - BrainDamaged - 02.12.2017

[Vehicles[i][vehModel] - 400]
Editing;
[Vehicles[i][vehModel] - 399]

Error Mesage: Accessing element at negative index -398


Re: [debug] Run time error 4: "Array index out of bounds" - RedFusion - 02.12.2017

Код:
COMMAND:myvehicles(playerid, params[])
{
	new bool:found = false, msg[256];
	for(new i = 0; i < MAX_VEH; i++)
	{
		if(!Vehicles[i][vehStatus]) continue;
		
		if(Vehicles[i][vehOwner] == Player[playerid][pID])
		{
                        new vehicleid = Vehicles[i][vehID], modelid = GetVehicleModel(vehicleid);

			found = true;

                        format(msg, sizeof(msg), "%s ID : "CHAT_YELLOW"%d"CHAT_WHITE"\n", vehicleNames[modelid - 400], vehicleid);
		}
	}
	if(found)
	{
		if(Player[playerid][english])
			ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_LIST, "My Vehicles", msg, "Choose", "Cancel");
		else
			ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_LIST, "Mobil Saya", msg, "Pilih", "Batal");
	}
	else
	{
		if(Player[playerid][english])
			Server(playerid, "You didn't have any vehicles.");
		else
			Server(playerid, "Kamu tidak memiliki kendaraan.");
	}
	return 1;
}
try this


Re: [debug] Run time error 4: "Array index out of bounds" - BrainDamaged - 02.12.2017

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
Код:
COMMAND:myvehicles(playerid, params[])
{
	new bool:found = false, msg[256];
	for(new i = 0; i < MAX_VEH; i++)
	{
		if(!Vehicles[i][vehStatus]) continue;
		
		if(Vehicles[i][vehOwner] == Player[playerid][pID])
		{
                        new vehicleid = Vehicles[i][vehID], modelid = GetVehicleModel(vehicleid);

			found = true;

                        format(msg, sizeof(msg), "%s ID : "CHAT_YELLOW"%d"CHAT_WHITE"\n", vehicleNames[modelid - 400], vehicleid);
		}
	}
	if(found)
	{
		if(Player[playerid][english])
			ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_LIST, "My Vehicles", msg, "Choose", "Cancel");
		else
			ShowPlayerDialog(playerid, DIALOG_MYVEHICLES, DIALOG_STYLE_LIST, "Mobil Saya", msg, "Pilih", "Batal");
	}
	else
	{
		if(Player[playerid][english])
			Server(playerid, "You didn't have any vehicles.");
		else
			Server(playerid, "Kamu tidak memiliki kendaraan.");
	}
	return 1;
}
try this
Oh No,
this time the server stops responding when I enter the command


Re: [debug] Run time error 4: "Array index out of bounds" - BrainDamaged - 02.12.2017

Please Help