What to use? Enum or Array?
#1

Hello guys,

Many of you use enums as of saving systems (register/login data), so I want to ask this question here. What if I would use all player data in one enum? I use enums only for saving dates, and arrays for temp data. So, if you don't understand me I'll give an example.

pawn Код:
enum pInfo
{
    pAdmin,
    pKills,
    pDeaths,
    pBanned,
    pVip
};
new PlayerData[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS char];
new gPlayerZone[MAX_PLAYERS char];
new gPlayerAFK[MAX_PLAYERS];
new gPlayerName[MAX_PLAYER_NAME];
new gPlayerIp[16];
// more
that's what I'm using currently. But could I move them to pInfo enum? And tell me please difference.

pawn Код:
enum pInfo
{
    pAdmin,
    pKills,
    pDeaths,
    pBanned,
    pVip,
    pLogged,
    pZone,
    pAFK,
    pName[MAX_PLAYER_NAME],
    pIp[16]
    // more
};
new PlayerData[MAX_PLAYERS][pInfo];
Thanks in advise.
Reply
#2

"Variable" not "array". Failed hard.
Reply
#3

You are using arrays in all the cases you have listed, however PlayerData is a two-dimensional array, MAX_PLAYERS * pInfo (where pInfo is really the total size of the 'pInfo' enumerator (which in your case is 8 + MAX_PLAYER_NAME + 16 (ip).
Then you just refer to the cell in the array basing on the enumerator.
So PlayerData[0][pDeaths] is really PlayerData[0][2] (pAdmin = 0, pKills = 1, pDeaths = 2)
Enumerator is not a data storage type, I think that the name 'enumerator' is clear enough.
You could have tried assigning 'default' values in the enum and thought it will set the data value by default to this one, like this:
Код:
enum test
{
    thingA,
    thingB = 13,
    thingC
};
Then you would notice that doing something like PlayerData[id][thingB] would return 0 instead of 13, thats because assigning 13 to thingB in the enumerator didn't really set the data to 13 but set the 'position' of thingB to 13, thus the array created basing on this enumerator now has 15 cells instead of 3 (which is just wasting the memory, because you won't access the rest of it)
Reply
#4

I will usually use enums when I know there is going to do be more than 2 variables you can do it either way but using an enum really helps to group all your related data.
Reply
#5

So that means no matter how I use? They are basically the same?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)