Error /fvr compile
#1

Hello everyone!

When i compile this command result this error
"error 032: array index out of bounds". Problem it's SAPDVehicles

What can i do ?

This is script
pawn Код:
new SAPDVehicles[20];




zcmd(fvr, playerid, params[])
{
    if(!IsPlayerConnectedEx(playerid)) return SendClientMessageEx(playerid, COLOR_GREY, NoConectado);
    {
        {
            if(Info[playerid][pLeader] > 0)
            {
                switch(Info[playerid][pLeader])
                {
                     case 1:
                    {
                        {
                            new bool:unwanted[MAX_VEHICLES];
                            foreach(Player, player)
                            {
                                if(IsPlayerInAnyVehicle(player))
                                {
                                    unwanted[GetPlayerVehicleID(player)]=true;
                                }
                            }
                            for(new car = SAPDVehicles[0]; car <= SAPDVehicles[52]; car++)
                            {
                                if(!unwanted[car]) SetVehicleToRespawn(car);
                            }
                        }

        }
                SendFamilyMessage(Info[playerid][pMember], 0xFE6C01FF, " All cars unused has been respawned by {FFFFFF}Leader");
            }
            else return SendClientMessageEx(playerid, COLOR_GREY, "You're not Leader!");
        }
    }
    return 1;
}
Please help me, thanks.
Reply
#2

hange this line:
PHP код:
for(new car SAPDVehicles[0]; car <= SAPDVehicles[52]; car++) 
to:
PHP код:
for(new car SAPDVehicles[0]; car <= SAPDVehicles[19]; car++) 
Also, I don't understand why you are using the variable SAPDVehicles[] this way
Reply
#3

You declare it with size of 20 and then trying to access element at index 52:
pawn Код:
car <= SAPDVehicles[52];
You need to loop 20 times as the size of the array and the ids are stored in SAPDVehicles[index].
pawn Код:
for (new car; car < sizeof SAPDVehicles; car++)
{
    if (SAPDVehicles[car] != INVALID_VEHICLE_ID && !unwanted[SAPDVehicles[car]]) SetVehicleToRespawn(SAPDVehicles[car]);
}
Reply
#4

Again


ERROR : C:\Documents and Settings\UserName\Desktop\GM\gamemodes\gm.pwn(4501 1) : error 032: array index out of bounds (variable "SAPDVehicles")
pawn Код:
new SAPDVehicles[20];

SAPDVehicles[0] = AddStaticVehicleEx(596,1601.872924,-1704.370971,5.612636,89.574440,0,1,TIME_RESPAWN);
..
SAPDVehicles[20] = AddStaticVehicleEx(596,1601.872924,-1704.370971,5.612636,89.574440,0,1,TIME_RESPAWN);

....

zcmd(fvr, playerid, params[])
{
    if(!IsPlayerConnectedEx(playerid)) return SendClientMessageEx(playerid, COLOR_GREY, NoConectado);
    {
        {
            if(Info[playerid][pLeader] > 0)
            {
                switch(Info[playerid][pLeader])
                {
                     case 1:
                    {
                        {
                            new bool:unwanted[MAX_VEHICLES];
                            foreach(Player, player)
                            {
                                if(IsPlayerInAnyVehicle(player))
                                {
                                    unwanted[GetPlayerVehicleID(player)]=true;
                                }
                            }
                            for(new v = SAPDVehicles[0]; v <= SAPDVehicles[20]; v++)
                            {
                                if(!unwanted[v]) SetVehicleToRespawn(v);
                            }
                        }
                    }
                }
                SendFamilyMessage(Info[playerid][pMember], 0xFE6C01FF, " All cars unused has been respawned by {FFFFFF}Leader");
            }
            else return SendClientMessageEx(playerid, COLOR_GREY, "You're not Leader!");
        }
    }
    return 1;
}

Where it's the problem?
Reply
#5

The index of the variable SAPDVehicles[20] is between 0 and 19. This results in 20.

Код:
SAPDVehicles[19] = AddStaticVehicleEx(596,1601.872924,-1704.370971,5.612636,89.574440,0,1,TIME_RESPAWN);
Reply
#6

Try to change this
PHP код:
for(new SAPDVehicles[0]; <= SAPDVehicles[20]; v++) 
to
PHP код:
for(new SAPDVehicles[0]; <= SAPDVehicles[19]; v++) 
EDIT: The last character of a array is '0/' or something like that. It's called null character in ascii.
Reply
#7

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Try to change this
PHP код:
for(new SAPDVehicles[0]; <= SAPDVehicles[20]; v++) 
to
PHP код:
for(new SAPDVehicles[0]; <= SAPDVehicles[19]; v++) 
EDIT: The last character of a array is '0/' or something like that. It's called null character in ascii.
SOLVED!
Thank you so much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)