SA-MP Forums Archive
Loop through enum items - 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: Loop through enum items (/showthread.php?tid=317889)



Loop through enum items - Nonameman - 12.02.2012

Hey!

Is there any way to loop through an array that has items of an enum?

pawn Код:
enum PlayerInfo { deaths, fstyle, kicks, kills, money, muted, mutes, rank, respect, score, skin };

new g_PlayerInfo[MAX_PLAYERS][PlayerInfo];
I ask it because using

pawn Код:
g_PlayerInfo[playerid][deaths] = 0;
g_PlayerInfo[playerid][fstyle] = 0;
g_PlayerInfo[playerid][kicks] = 0;
...
when a player connects is more complicated if you have much more enum items.


Thanks
Nonameman


Re: Loop through enum items - Madd Kat - 12.02.2012

Yes just do the loop and replace the field with your loop.
Leave the player id alone

g_PlayerInfo[playerid][i] = 0


Re: Loop through enum items - Nonameman - 13.02.2012

No, I know how to loop through a normal array, but it generates tag mismatch error, it can't be indexed with integer values.


Re: Loop through enum items - [Diablo] - 13.02.2012

pawn Код:
for(new i; PlayerInfo:i < PlayerInfo; i++)
{
     g_PlayerInfo[playerid][PlayerInfo:i] = 0;
}
something like this should do it..

edit: not tested atm.


Re: Loop through enum items - Nonameman - 13.02.2012

Thank you so much, this solved my problem.
Can I ask you to explain me who is it works? It's like an iterator?


Re: Loop through enum items - [Diablo] - 13.02.2012

the enum name is also the tag of the index variable.


Re: Loop through enum items - Nonameman - 13.02.2012

Thank you.


Re: Loop through enum items - Madd Kat - 15.02.2012

https://sampforum.blast.hk/showthread.php?tid=318307


Actually what i posted does work via the link above


Re: Loop through enum items - Dubya - 26.02.2014

hint: you could also use the _ key for this:
pawn Код:
for(new i; _:i < PlayerInfo; i++)
{
     g_PlayerInfo[playerid][PlayerInfo:i] = 0;
}