sizeof through an array
#1

I have this enum;

pawn Код:
enum pVars
{
    Password[129],
    Admin,
   
    WeaponKills[46]
}
new
    PlayerInfo[MAX_PLAYERS][pVars],
    bool: is_logged[MAX_PLAYERS];
Pretty standard, but I'm trying to access the amount of cells in "WeaponKills" which is currently 46.

I was going to do it like this;

pawn Код:
for(new i; i < sizeof(PlayerInfo[playerid][WeaponKills]); i++)
{
}
But obviously since I'm here, it doesn't work. How would I go about doing that?
Reply
#2

You cannot use sizeof with enums so use the size instead.

pawn Код:
for(new i; i < 46; i++)
Reply
#3

What Konstantinos said but I'm going to add this when these sort of situations come up use a #define of course.

#define WEAPON_KILL_SIZE 46
Reply
#4

Just going to combine what Konstantinos and [uL]Pottus said :P

pawn Код:
#define WEAPON_KILL_SIZE (46)

enum pVars
{
    Password[ 129 ],
    Admin,
    WeaponKills[ WEAPON_KILL_SIZE ]
}

new
    PlayerInfo[ MAX_PLAYERS ][ pVars ],
    bool: is_logged[ MAX_PLAYERS ];
Loop
pawn Код:
new i = 0;
while(i < WEAPON_KILL_SIZE)
{
    //Your code.
    i++;
}

// or

for(new i = 0; i < WEAPON_KILL_SIZE; i++)
{
    //Your code
}
Reply
#5

Thanks guys, wasn't sure if there was another way to do it. Had that way as a placeholder anyway - thanks again.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)