[Ajuda] array index out of bounds - wtf?
#1

Estб dando o seguinte erro na hora de compilar :

PHP код:
array index out of bounds (variable "Checkpoints1"
na linha:

pawn Код:
SetPlayerRaceCheckpoint(i, 0, Checkpoints1[1][1], Checkpoints1[1][2], Checkpoints1[1][3], Checkpoints1[2][1], Checkpoints1[2][2], Checkpoints1[2][3], 10);
cуdigo:

pawn Код:
if(IsPlayerAdmin(playerid))
         {
             for(new i = 0; i < GetMaxPlayers(); i++)
             {
                  if(IsPlayerConnected(i))
                  {
                      SetPlayerRaceCheckpoint(i, 0, Checkpoints1[1][1], Checkpoints1[1][2], Checkpoints1[1][3], Checkpoints1[2][1], Checkpoints1[2][2], Checkpoints1[2][3], 10);
                      Stats[i] = 1;
                      return 1;
                  }
             }
         }
         else
         {
             SendClientMessage(playerid, COLOR_RED, "Apenas Para Admins");
         }
pawn Код:
new Float:Checkpoints1[4][3] =
{
    {-2350.8674,-2184.8306,33.7524},
    {-2245.6699,-2127.4106,63.6550},
    {-2162.8430,-2041.3333,92.0730},
    {-2099.5679,-1893.6139,109.7994}
};
O que й? como resolver ?
Reply
#2

pawn Код:
SetPlayerRaceCheckpoint(i, 0, Checkpoints1, Checkpoints1, Checkpoints1, Checkpoints1, Checkpoints1, Checkpoints1, 10);

new Float:Checkpoints1[4][5] =
{
    {-2350.8674,-2184.8306,33.7524},
    {-2245.6699,-2127.4106,63.6550},
    {-2162.8430,-2041.3333,92.0730},
    {-2099.5679,-1893.6139,109.7994}
};
Reply
#3

Quote:
Originally Posted by mau.tito
Посмотреть сообщение
pawn Код:
SetPlayerRaceCheckpoint(i, 0, Checkpoints1, Checkpoints1, Checkpoints1, Checkpoints1, Checkpoints1, Checkpoints1, 10);

new Float:Checkpoints1[4][5] =
{
    {-2350.8674,-2184.8306,33.7524},
    {-2245.6699,-2127.4106,63.6550},
    {-2162.8430,-2041.3333,92.0730},
    {-2099.5679,-1893.6139,109.7994}
};
Dorgas? o.O

Assim dб:
pawn Код:
new Float:CheckCorrida[][] =
{
    {-2350.8674,-2184.8306,33.7524},
    {-2245.6699,-2127.4106,63.6550},
    {-2162.8430,-2041.3333,92.0730},
    {-2099.5679,-1893.6139,109.7994}
};
pawn Код:
SetPlayerRaceCheckpoint(i, 0, CheckCorrida[0][0], CheckCorrida[0][1], CheckCorrida[0][2], CheckCorrida[1][0], CheckCorrida[1][1], CheckCorrida[1][2], 10);
Tem que comeзar do 0 :P
Reply
#4

Obrigado humildadeforever.

Mas nesse caso, faзo oque? :

pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
    for(new i = 0; i < GetMaxPlayers(); i++)
    {
        switch(Stats[playerid])
        {
            case 1:
            {
                DisablePlayerRaceCheckpoint(playerid);
                SetPlayerRaceCheckpoint(playerid, 0, CPC1[2][1], CPC1[2][2], CPC1[2][3], CPC1[3][1], CPC1[3][2], CPC1[3][3], 10);
                Stats[i] = 2;
                return 1;
            }
            case 2:
            {
                DisablePlayerRaceCheckpoint(playerid);
                SetPlayerRaceCheckpoint(playerid, 0, CPC1[3][1], CPC1[3][2], CPC1[3][3], CPC1[4][1], CPC1[4][2], CPC1[4][3], 10);
                Stats[i] = 3;
                return 1;
            }
            case 3:
            {
                DisablePlayerRaceCheckpoint(playerid);
                SetPlayerRaceCheckpoint(playerid, 1, CPC1[4][1], CPC1[4][2], CPC1[4][3], CPC1[4][1], CPC1[4][2], CPC1[4][3]-5, 10);
                Stats[i] = 4;
                return 1;
            }
            case 4:
            {
                DisablePlayerRaceCheckpoint(playerid);
                GameTextForPlayer(playerid, "You have won the race!!", 3000, 1);
                GivePlayerMoneyEx(playerid, 10000);
                return 1;
            }
        }
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by AiaN
Посмотреть сообщение
Obrigado humildadeforever.

Mas nesse caso, faзo oque? :

pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
    for(new i = 0; i < GetMaxPlayers(); i++)
    {
        switch(Stats[playerid])
        {
            case 1:
            {
                DisablePlayerRaceCheckpoint(playerid);
                SetPlayerRaceCheckpoint(playerid, 0, CPC1[2][1], CPC1[2][2], CPC1[2][3], CPC1[3][1], CPC1[3][2], CPC1[3][3], 10);
                Stats[i] = 2;
                return 1;
            }
            case 2:
            {
                DisablePlayerRaceCheckpoint(playerid);
                SetPlayerRaceCheckpoint(playerid, 0, CPC1[3][1], CPC1[3][2], CPC1[3][3], CPC1[4][1], CPC1[4][2], CPC1[4][3], 10);
                Stats[i] = 3;
                return 1;
            }
            case 3:
            {
                DisablePlayerRaceCheckpoint(playerid);
                SetPlayerRaceCheckpoint(playerid, 1, CPC1[4][1], CPC1[4][2], CPC1[4][3], CPC1[4][1], CPC1[4][2], CPC1[4][3]-5, 10);
                Stats[i] = 4;
                return 1;
            }
            case 4:
            {
                DisablePlayerRaceCheckpoint(playerid);
                GameTextForPlayer(playerid, "You have won the race!!", 3000, 1);
                GivePlayerMoneyEx(playerid, 10000);
                return 1;
            }
        }
    }
    return 1;
}
Estб dando erro tambйm? Se tiver, tente fazer como eu fiz no outro cуdigo. 1 troque por 0, 2 por 1, 3 por 2, e por aн vai.
Reply
#6

Estб dando o mesmo erro.

Preciso que ao passar por um CP ele "set" o outro, e assim sucessivamente..

Entгo oque devo fazer й tirar aquele SetRaceCheckpoint do comando e comeзar do 0 dentro do OnPlayerEnterCheckPoint ?
Reply
#7

Erro proveniente de quando vocк faz a requisiзгo de um нndice que ultrapasse o tama nho da array

Exemplo:

new arr[5];

note que arr sу tem 5 partes, podendo ser acessada de arr[0] atй arr[4]

Caso eu pedir, arr[8] darб erro, pois arr nгo tem este нndice declarado!

__

Agora olhe para seu cуdigo e note o que vocк fez:

SetPlayerRaceCheckpoint(i, 0, Checkpoints1[1][1], Checkpoints1[1][2], Checkpoints1[1][3], Checkpoints1[2][1], Checkpoints1[2][2], Checkpoints1[2][3], 10);



Sendo que checkpoints foi declarado da seguinte maneira

PHP код:
new Float:Checkpoints1[4][3
Logo vocк sу pode acessar atй o Checkpoints1[x][2], comecando por Checkpoints1[x][0] e nгo por Checkpoints1[x][1] ao Checkpoints1[x][3]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)