Accessing element at negative index -400
#1

Код 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;
}
Reply
#2

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.
Reply
#3

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)?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)