Array index out of bounds
#1

pawn Код:
public SaveAccount(playername[])
{
    new string3[32];
    //GetPlayerName(MAX_PLAYERS, playername, MAX_PLAYER_NAME);
    format(string3, sizeof(string3), "users/%s.ini", playername);
    new File: hFile = fopen(string3, io_write);
    if (hFile)
    {
        new var[156];
        format(var, 32, "BT=%d\n",BT[MAX_PLAYERS]);fwrite(hFile, var);
        fclose(hFile);
    }
    return 1;
}
returns error:
Quote:

error 032: array index out of bounds (variable "BT")

Reply
#2

What is the size of BT? I assume it's MAX_PLAYERS. Therefore you can't access element 'MAX_PLAYERS' - because the first element index is 0, so if MAX_PLAYERS is 69 you can only access array indexes from 0 to 68.
Reply
#3

You're outside the bounds of the BT[MAX_PLAYERS]. Simple put [MAX_PLAYERS] on where you have defined the array.
Reply
#4

Make sure when you create global variables, MAX_PLAYERS is out of a callback, so when you use that variable later on, you can use the playerid inside of the variable. Example:

pawn Код:
// top of script

new BT[MAX_PLAYERS];

// in a command you would use it like this for example:

BT[playerid]
So basically, you need to change BT[MAX_PLAYERS] to BT[playerid]
Reply
#5

The way to fix it is to change BT[MAX_PLAYERS] to BT[MAX_PLAYERS-1] on the save part.
Thank you all for attempting to solve it.
Reply
#6

Quote:
Originally Posted by maramizo
Посмотреть сообщение
The way to fix it is to change BT[MAX_PLAYERS] to BT[MAX_PLAYERS-1] on the save part.
Thank you all for attempting to solve it.
That will stop the error but your code will not do what you want it to do. Whatever BT is it will be the same for every player because you only ever use MAX_PLAYERS-1 as an index and not the playerid. So you might aswel use a normal var (none array) since you only ever use one index.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)