Accessing element at negative index -400 - 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: Accessing element at negative index -400 (
/showthread.php?tid=572035)
Accessing element at negative index -400 -
rOps - 24.04.2015
Код HTML:
[22:07:56] [debug] Run time error 4: "Array index out of bounds"
[22:07:56] [debug] Accessing element at negative index -400
[22:07:56] [debug] AMX backtrace:
[22:07:56] [debug] #0 000223ec in public OnDialogResponse () from LTGRP.amx
Код:
new String[128];
format(String, sizeof(String), "{94CB80}• Pardavėte transportą {ff0000}%s {94CB80}uћ {ff0000}%sЂ{94CB80}.", VehicleNames[GetVehicleModel(vehicleid) - 400], FormatuotiSkaicius(MoneyCount));
SendClientMessage(playerid, -1, String);
Код HTML:
stock FormatuotiSkaicius(Number)
{
new String[128];
format(String, sizeof(String), "%d", Number);
if(-1000 < Number < 1000) return String;
new Minus = 0;
if(Number < 0) Minus = 1;
new Length = strlen(String);
while((Length -= 3) > Minus) strins(String, ",", Length);
return String;
}
Re: Accessing element at negative index -400 -
Konstantinos - 24.04.2015
The vehicle does not exist (invalid) so GetVehicleModel returns 0. You can prevent it and if the vehicle does not exist, it'll print "N/A" instead:
pawn Код:
new String[128], modelid = GetVehicleModel(vehicleid);
format(String, sizeof(String), "{94CB80}• Pardavėte transportą {ff0000}%s {94CB80}uћ {ff0000}%sЂ{94CB80}.", (modelid) ? (VehicleNames[modelid - 400]) : ("N/A"), FormatuotiSkaicius(MoneyCount));
SendClientMessage(playerid, -1, String);
However, I'd suggest to check if the modelid is not valid and don't send the message at all.
Re: Accessing element at negative index -400 -
rOps - 24.04.2015
Quote:
Originally Posted by Konstantinos
The vehicle does not exist (invalid) so GetVehicleModel returns 0. You can prevent it and if the vehicle does not exist, it'll print "N/A" instead:
pawn Код:
new String[128], modelid = GetVehicleModel(vehicleid);
format(String, sizeof(String), "{94CB80}• Pardavėte transportą {ff0000}%s {94CB80}uћ {ff0000}%sЂ{94CB80}.", (modelid) ? (VehicleNames[modelid - 400]) : ("N/A"), FormatuotiSkaicius(MoneyCount)); SendClientMessage(playerid, -1, String);
However, I'd suggest to check if the modelid is not valid and don't send the message at all.
|
Thanks, it works. But why in another code it works too (as on the my example)?