Array index out of bounds Errors. - 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 Errors. (
/showthread.php?tid=515681)
Array index out of bounds Errors. -
rappy93 - 27.05.2014
Код:
[17:11:18] [debug] Run time error 4: "Array index out of bounds"
[17:11:18] [debug] Accessing element at index 10 past array upper bound 9
[17:11:18] [debug] AMX backtrace:
[17:11:18] [debug] #0 00064d40 in AssignVehicleTickets (vehicleid=71, tickets[]=@0x05edbb68 "0|0|0|0|0|0|0|0|0|0") at E:\Multe\Servere SA-MP\Rappy GM\LS-RP Main Server Files\gamemodes\lsrp.pwn:5005
[17:11:18] [debug] #1 000e7b2c in public OnPlayerSpawnVehicle (playerid=0, slot=2) at E:\Multe\Servere SA-MP\Rappy GM\LS-RP Main Server Files\gamemodes\lsrp.pwn:14612
[17:11:30] [debug] Run time error 4: "Array index out of bounds"
[17:11:30] [debug] Accessing element at index 10 past array upper bound 9
[17:11:30] [debug] AMX backtrace:
[17:11:30] [debug] #0 000649f0 in CountVehicleTickets (vehicle=71) at E:\Multe\Servere SA-MP\Rappy GM\LS-RP Main Server Files\gamemodes\lsrp.pwn:4978
[17:11:30] [debug] #1 00096970 in public RL_OnPlayerStateChange (playerid=0, newstate=2, oldstate=1) at E:\Multe\Servere SA-MP\Rappy GM\LS-RP Main Server Files\gamemodes\lsrp.pwn:9130
[17:11:30] [debug] #2 native CallLocalFunction () [00472ad0] from samp-server.exe
[17:11:30] [debug] #3 00031138 in public OnPlayerStateChange (playerid=0, newstate=2, oldstate=1) at E:\Multe\Servere SA-MP\Rappy GM\LS-RP Main Server Files\pawno\include\OPSP.inc:304
[17:12:04] [debug] Run time error 4: "Array index out of bounds"
[17:12:04] [debug] Accessing element at index 10 past array upper bound 9
AssignVehicleTickes :
pawn Код:
stock AssignVehicleTickets(vehicleid, tickets[])
{
new tmp[MAX_CAR_TICKETS][32];
explode(tmp, tickets, "|");
for(new i = 0; i < MAX_CAR_TICKETS; i ++)
{
VehicleInfo[vehicleid][carTicket][i] = strval(tmp[i]);
}
}
CountVehicleTickets:
pawn Код:
stock CountVehicleTickets(vehicle)
{
new count = 0;
for(new i = 0; i < MAX_CAR_TICKETS; i++)
{
if(VehicleInfo[vehicle][carTicket][i] != 0)
{
count++;
}
}
return count;
}
I dont really know why these erros are showing up.
Note : They show up when I spawn my private vehicle.
Re: Array index out of bounds Errors. -
Konstantinos - 27.05.2014
The size of carTicket is 10. Is MAX_CAR_TICKETS defined as 10 as well? If it's any value higher than that, it will cause the run time error 4.
Re: Array index out of bounds Errors. -
rappy93 - 27.05.2014
pawn Код:
#define MAX_CAR_TICKETS 30
Nope. What value should it have?
Re: Array index out of bounds Errors. -
Konstantinos - 27.05.2014
The same value as the size of carTicket (from the enum) which is 10.
pawn Код:
#define MAX_CAR_TICKETS 10
In case you change the one so it won't cause any problems, change it to:
pawn Код:
// in enum:
carTicker[MAX_CAR_TICKETS], // if it's last, don't use the comma
Re: Array index out of bounds Errors. -
rappy93 - 27.05.2014
Damn... Thank you very much. I keep learing new things from ya. I'll +rep if I can do it yet