Array index out of bounds
#1

Help me solve this please:

Код:
[02:54:02] [debug] AMX backtrace:
[02:54:02] [debug] #0 002055a8 in ?? () from truck.amx
[02:54:02] [debug] #1 002046c8 in public Speedometer_Update () from truck.amx
[02:54:02] [debug]  Accessing element at index 100 past array upper bound 99
pawn Код:
public Speedometer_Update(playerid)
{
    // Setup local variables
    new vehicleid, Float:speed_x, Float:speed_y, Float:speed_z, Float:final_speed, speed_string[50], final_speed_int;//, Float:vehiclehealth;
    new FuelString[50], FuelStatus[20];
    new Msg[128], Name[24];

    // Get the ID of the player's vehicle
    vehicleid = GetPlayerVehicleID(playerid);

    //******************************************************************************************************************************
    // Anti-hack stuff
    //******************************************************************************************************************************

    AntiHack(playerid);

    //******************************************************************************************************************************
    // End of anti-hack stuff
    //******************************************************************************************************************************

    // Check and toggle spectate-mode when needed (when target player entered or exited his vehicle)
    if (GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
    {
        // Get the target player's ID and name
        new OtherPlayer = APlayerData[playerid][SpectateID];
        GetPlayerName(OtherPlayer, Name, sizeof(Name));

        // Use the same worldid and interiorid as the OtherPlayer
        SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(OtherPlayer));
        SetPlayerInterior(playerid, GetPlayerInterior(OtherPlayer));

        // Check if the player is spectating a player
        if (APlayerData[playerid][SpectateType] == ADMIN_SPEC_TYPE_PLAYER)
        {
            // Check if the target player has entered a vehicle
            if (GetPlayerVehicleSeat(OtherPlayer) != -1)
            {
                // Change spectate mode to vehicle
                PlayerSpectateVehicle(playerid, GetPlayerVehicleID(OtherPlayer));
                APlayerData[playerid][SpectateID] = OtherPlayer;
                APlayerData[playerid][SpectateVehicle] = GetPlayerVehicleID(OtherPlayer);
                APlayerData[playerid][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
                format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} has entered a vehicle, changing spectate mode to match", Name);
                SendClientMessage(playerid, 0xFFFFFFFF, Msg);
            }
        }
        else // The player is spectating a vehicle
        {
            // Check if the target player has exited a vehicle
            if (GetPlayerVehicleSeat(OtherPlayer) == -1)
            {
                // Change spectate mode to player
                PlayerSpectatePlayer(playerid, OtherPlayer);
                SetPlayerInterior(playerid, GetPlayerInterior(OtherPlayer));
                APlayerData[playerid][SpectateID] = OtherPlayer;
                APlayerData[playerid][SpectateType] = ADMIN_SPEC_TYPE_PLAYER;
                format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} has exited a vehicle, changing spectate mode to match", Name);
                SendClientMessage(playerid, 0xFFFFFFFF, Msg);
            }
        }
    }

    // When the player got a wanted level and a police player warned him to stop, a timer is started and a variable is set to "true"
    // Check if this variable has been set
    if (APlayerData[playerid][PoliceWarnedMe] == true)
    {
        // Check if the player has no wanted level anymore (after finishing a overloaded mission, player got fined, ...)
        if (GetPlayerWantedLevel(playerid) == 0)
        {
            APlayerData[playerid][PoliceCanJailMe] = false; // Clear the variable
            APlayerData[playerid][PoliceWarnedMe] = false; // Clear the variable
            APlayerData[playerid][Value_PoliceCanJailMe] = 0; // Clear the remaining time for the timer
            KillTimer(APlayerData[playerid][Timer_PoliceCanJailMe]); // Kill the timer
        }
    }

    // If the player is inside a vehicle
    if(vehicleid != 0)
    {
        // Get the vehicles velocity
        GetVehicleVelocity(vehicleid, speed_x, speed_y, speed_z);
        // Calculate the speed (in kph)
        final_speed = floatsqroot(((speed_x * speed_x) + (speed_y * speed_y)) + (speed_z * speed_z)) * 158.179;
        // Convert the float value to an int value
        final_speed_int = floatround(final_speed, floatround_round);
        // Also save the speed for the player
        APlayerData[playerid][PlayerSpeed] = final_speed_int;
        // Setup the string to display for the player and display it
        format(speed_string, 50, "KMH: %i", final_speed_int);
        TextDrawSetString(Velocimetro[playerid], speed_string);
 

        // Add the speed to the stats (this will be the meters driven in total)
        APlayerData[playerid][StatsMetersDriven] = APlayerData[playerid][StatsMetersDriven] + (final_speed / 7.2);

        // Also display the vehicle's health through the player-health bar
        //GetVehicleHealth(vehicleid, vehiclehealth);
        //SetPlayerHealth(playerid, vehiclehealth / 10.0);

        // Check if the speed is above 10kph and the fuel of the vehicle isn't empty yet
        if ((final_speed_int > 10) && (AVehicleData[vehicleid][Fuel] > 0))
            AVehicleData[vehicleid][Fuel] = AVehicleData[vehicleid][Fuel] - 1; // Decrease the fuel for this vehicle every time the timer is run

        // Construct the fuelgauge
        if ((AVehicleData[vehicleid][Fuel] > 0) && (AVehicleData[vehicleid][Fuel] < 100000))
            format(FuelStatus, 20, "~g~%s~r~%s", "•", "IIIIIIIII"); // Fuel is between 0% and 10% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 1)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 2)))
            format(FuelStatus, 20, "~g~%s~r~%s", "II", "IIIIIIII"); // Fuel is between 10% and 20% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 2)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 3)))
            format(FuelStatus, 20, "~g~%s~r~%s", "III", "IIIIIII"); // Fuel is between 20% and 30% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 3)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 4)))
            format(FuelStatus, 20, "~g~%s~r~%s", "IIII", "IIIIII"); // Fuel is between 30% and 40% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 4)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 5)))
            format(FuelStatus, 20, "~g~%s~r~%s", "IIIII", "IIIII"); // Fuel is between 40% and 50% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 5)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 6)))
            format(FuelStatus, 20, "~g~%s~r~%s", "IIIIII", "IIII"); // Fuel is between 50% and 60% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 6)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 7)))
            format(FuelStatus, 20, "~g~%s~r~%s", "IIIIIII", "III"); // Fuel is between 60% and 70% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 7)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 8)))
            format(FuelStatus, 20, "~g~%s~r~%s", "IIIIIIII", "II"); // Fuel is between 70% and 80% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 8)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 9)))
            format(FuelStatus, 20, "~g~%s~r~%s", "IIIIIIIII", "I"); // Fuel is between 80% and 90% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 9)) && (AVehicleData[vehicleid][Fuel] <= MaxFuel))
            format(FuelStatus, 20, "~g~%s", "IIIIIIIIII"); // Fuel is between 90% and 100% full (all bars are green)

        if (AVehicleData[vehicleid][Fuel] == 0)
            format(FuelStatus, 20, "~r~%s", "IIIIIIIIII"); // Fuel is empty (all bars are red)

        // Format the final fuel-gauge readout
        format(FuelString, 50, "%s", FuelStatus);
        // Display the fuel-gauge
        TextDrawSetString(Gasolina[playerid], FuelString);
 

        // Check if the vehicle is out of fuel
        if (AVehicleData[vehicleid][Fuel] == 0)
        {
            // Stop the engine and turn off the lights
            new engine,lights,alarm,doors,bonnet,boot,objective;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
        }

        // Check if the player is not in any plane or helicopter (those cannot be caught by speedcamera's)
        if (IsVehicleAirVehicle(vehicleid) == 0)
            if (APlayerData[playerid][PlayerClass] != ClassPolice) // Check if the player isn't speeding (cops won't get caught)
                CheckPlayerSpeeding(playerid);
    }
    else
    {
        // If the player is not inside a vehicle, display an empty string (looks like the speedometer is gone)
        TextDrawSetString(Velocimetro[playerid], " ");
        TextDrawSetString(Gasolina[playerid], " ");
        // Set the speed of the player to 0
        APlayerData[playerid][PlayerSpeed] = 0;
    }
}
Reply
#2

Increase the size of your arrays.
Reply
#3

but still did it anyway.
Reply
#4

Show code from the function call
Reply
#5

pawn Код:
public OnPlayerConnect(playerid){
APlayerData[playerid][SpeedometerTimer] = SetTimerEx("Speedometer_Update", 500, true, "i", playerid);
Reply
#6

help
Reply
#7

If you compile with -d3 you will also be given the line of the occuring error. To do this, simply open up notepad and type "-d3" and save it as "pawn.cfg" and put it in your pawno folder (where pawncc.exe is located). You may then look at the error again and see it will specify the line of the error at the end of the line. This will make it even easier to find and fix it.

Out from the crashdetect error I know that you have an array with 100 cells (0-99) and you're trying to use cell #101 (100) which is non-existent. You need to increase the size of the correct array. By doing what I said above, you will very easily locate this array and fix the problem.
Reply
#8

Quote:

If you compile with -d3 you will also be given the line of the occuring error. To do this, simply open up notepad and type "-d3" and save it as "pawn.cfg" and put it in your pawno folder (where pawncc.exe is located). You may then look at the error again and see it will specify the line of the error at the end of the line. This will make it even easier to find and fix it.

Out from the crashdetect error I know that you have an array with 100 cells (0-99) and you're trying to use cell #101 (100) which is non-existent. You need to increase the size of the correct array. By doing what I said above, you will very easily locate this array and fix the problem.

Error:

Код:
'7(0) : error fatal: 102: table overflow: "option table"
line out of reach
Reply
#9

Help?
Reply
#10

What did you do to cause such error?

Quote:
Originally Posted by PAWN Language Guide (PDF)
table overflow: table name
An internal table in the pawn parser is too small to hold the required
data. Some tables are dynamically growable, which means that there
was insucient memory to resize the table. The \table name" is one
of the following:

"option table": in case that there are more options on the command
line or in the response file than the compiler can cope with.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)