SA-MP Forums Archive
invalid array size (negative, zero or out of bounds) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: invalid array size (negative, zero or out of bounds) (/showthread.php?tid=453468)



invalid array size (negative, zero or out of bounds) - Kyra - 25.07.2013

Hi i want to optimise my code, but i have error with this code how i can solved my error?

PHP код:
new MAXNUMBERTEAMID;
    foreach(new 
Player)
    {
        if(
gLogged[i])
        {
            if(
MAXNUMBERTEAMID PlayerInfo[i][pTeamId] && PlayerInfo[i][pTeamId] > 0MAXNUMBERTEAMID PlayerInfo[i][pTeamId];
        }
    }
    new 
TeamConnected[MAXNUMBERTEAMID+1];// error is here 



Re: invalid array size (negative, zero or out of bounds) - DobbysGamertag - 25.07.2013

Try declaring it with a size.

pawn Код:
#define MAX_NUMBERTEAMID 249 //above your code provided.
Hope it helped. If it didnt sorry.


Re: invalid array size (negative, zero or out of bounds) - Pottus - 25.07.2013

You can't dynamically initialize arrays in this manner.


Re: invalid array size (negative, zero or out of bounds) - Kyra - 25.07.2013

Quote:
Originally Posted by DobbysGamertag
Посмотреть сообщение
Try declaring it with a size.

pawn Код:
#define MAX_NUMBERTEAMID 249 //above your code provided.
Hope it helped. If it didnt sorry.
Thanks but don't work

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
You can't dynamically initialize arrays in this manner.
How i can do this?


Re: invalid array size (negative, zero or out of bounds) - Pottus - 25.07.2013

I don't really see the need for it with what your trying to do.


Re: invalid array size (negative, zero or out of bounds) - Kyra - 25.07.2013

Beacause i want to calculate the number at all team in game and i use 1 loop on a loop it's too much

PHP код:
new COUNTMYTEAM,CountOtherTeam[MAX_PLAYERS],MAXINTEAM;
    foreach(new 
Player)
    {
        if(
gLogged[i])
        {
            if(
PlayerInfo[i][pTeamId] > && GetPlayerTeam(i) == CLAN+PlayerInfo[i][pTeamId])
            {
                if(
PlayerInfo[i][pTeamId] == PlayerInfo[playerid][pTeamId]) COUNTMYTEAM++;
                foreach(new 
Player)
                {
                    if(
gLogged[e])
                    {
                        if(
PlayerInfo[e][pTeamId] == PlayerInfo[i][pTeamId] && PlayerInfo[e][pTeamId] != PlayerInfo[playerid][pTeamId]) CountOtherTeam[e]++;
                        if(
MAXINTEAMCountOtherTeam[e]) MAXINTEAMCountOtherTeam[e];
                    }
                }
            }
        }
    }
       if(
COUNTMYTEAM 1)
       {
          
// code...
        
}
    return 
1