Accessing element at negative index -400
#5

pawn Код:
function Veh_Speedo( )
{
    new sp_string[ 60 ], liSpeed;
    foreach( Player, i )
    {
        if( ! SpeedoStats[ i ] ) continue;
        new model = GetVehicleModel( GetPlayerVehicleID( i ) );
        if(!model) continue;
        liSpeed = GetPlayerSpeed( i, true );
        format( sp_string, sizeof(sp_string), "~w~~h~'  ~r~~h~Vehicle: ~w~~h~%s", vehName[ model - 400 ] );
        PlayerTextDrawSetString( i, Speedo_TD[ 0 ], sp_string );
        format( sp_string, sizeof(sp_string), "~b~~h~KM/h: ~w~~h~%d", liSpeed );
        PlayerTextDrawSetString( i, Speedo_TD[ 1 ], sp_string );
    }
    return true;
}
Using 256 cells when only 60 cells or even less is necessary is not practical. You need to make sure both vehicle model and vehicle ID are valid before even thinking of putting them into an array. Unexpected or invalid values will cause out of bounds errors. 'GetVehicleModel' returns either the vehicle model or '0' if the vehicle does not exist. So you can do both a valid vehicle and valid model check in one simple execution of 'GetVehicleModel(GetPlayerVehicleID(i));'
Reply


Messages In This Thread
Accessing element at negative index -400 - by nGen.SoNNy - 18.11.2014, 07:55
Re: Accessing element at negative index -400 - by xCrazyMonkey - 18.11.2014, 08:14
Re: Accessing element at negative index -400 - by oliverrud - 18.11.2014, 08:22
Re: Accessing element at negative index -400 - by nGen.SoNNy - 18.11.2014, 10:01
Re: Accessing element at negative index -400 - by Threshold - 18.11.2014, 11:41
Re: Accessing element at negative index -400 - by nGen.SoNNy - 18.11.2014, 13:26

Forum Jump:


Users browsing this thread: 3 Guest(s)