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: Array Index Out Of Bounds (
/showthread.php?tid=605162)
Array Index Out Of Bounds -
Dokins - 15.04.2016
Error line, returned in compiler. I'm not sure what's causing the issue.
MAX_VEHICLES is 500.
I'm not sure of the actual issue with the line.
Could someone kindly assist me?
pawn Код:
format(string, sizeof(string), "%sVehicle: %s | Plate: %s\n", string, VehicleNames[name], VehPlate[x]);
pawn Код:
CMD:collectvehicle(playerid, params[])//here
{
if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
new string[512], am, name;
for(new x = 0; x < MAX_VEHICLES; x++)
{
name = GetVehicleModel(x) - 400;
if(VehOwner[x] == PlayerSQLID[playerid])
{
am ++;
}
if(RepairTime[x] == 0 && am == 1)
{
VehRepairList[x]= 0;
format(string, sizeof(string), "Vehicle: %s | Plate: %s\n", VehicleNames[name], VehPlate[x]);
}
if(am > 1)
{
VehRepairList[x] = am - 1;
format(string, sizeof(string), "%sVehicle: %s | Plate: %s\n", string, VehicleNames[name], VehPlate[x]);
}
}
if(am == 0)return SendClientMessage(playerid, COLOUR_GREY, "You do not have any vehicles awaiting collection.");
ShowPlayerDialog(playerid, DIALOG_COLLECTVEH, DIALOG_STYLE_LIST, "Vehicles Awaiting Collection", string, "Select","Close");
return 1;
}
Re: Array Index Out Of Bounds -
Godey - 15.04.2016
Don't you think you should use it like this?
Код:
format(string, sizeof(string), "Vehicle: %s | Plate: %s\n", VehicleNames[name], VehPlate[x]);
SendClientMessage(playerid, -1, string);
Re: Array Index Out Of Bounds -
Konstantinos - 15.04.2016
If a vehicle does not exist,
GetVehicleModel returns 0 so subtracting 400 from it is negative index -400.
By the way, vehicle IDs start from 1. Using
GetVehiclePoolSize or better yet
foreach (if you create vehicles only in a single script) is better.
Re: Array Index Out Of Bounds -
Dokins - 15.04.2016
Ahhhh thanks Konstantinos, again.
Godey, the way it works it has to retrieve multiple inputs.
They do?
Since when? aha...