Something new in enums
#1

I've been reading up the wiki, and saw something new:
pawn Код:
enum (<<= 1)
{
    TEAM_NONE,
    TEAM_COP = 1,
    TEAM_ROBBER,
    TEAM_CIV,
    TEAM_CLERK,
    TEAM_DRIVER,
    TEAM_ADMIN
}
, as it stated, you can use a few teams in a variable like this:
pawn Код:
gPlayerTeam[playerid] |= TEAM_COP;
So, my question is, can i add unlimited items like that? Would be nice to store my whole player inventory in one variable
Reply
#2

Probably, check it.
Reply
#3

Quote:
Originally Posted by Darnell
Посмотреть сообщение
Probably, check it.
Thanks for the info.. I don't want responses like that!
Reply
#4

afaik, this method is for checking a bit for true or false. if iam not wrong, its possible to store 32 teams in a single cell this way. (4 bytes == 32 bits)..
oh, iam not sure about the enumerator increasement.. the <<= is a logical shift, isnt it? so the enum would power up the values by shifting the "adressed" bit to be these values: 1, 2, 4, 8, 16, 32.. so 0b00000001=TEAM_COP, 0b00000010=TEAM_ROBBER, and 0b00000100=TEAM_CIV...
0b00000111 would be 7 (1+2+4), or the 3 teams gathered together
Reply
#5

Quote:
Originally Posted by Babul
Посмотреть сообщение
afaik, this method is for checking a bit for true or false. if iam not wrong, its possible to store 32 teams in a single cell this way. (4 bytes == 32 bits)..
oh, iam not sure about the enumerator increasement.. the <<= is a logical shift, isnt it? so the enum would power up the values by shifting the "adressed" bit to be these values: 1, 2, 4, 8, 16, 32.. so 0b00000001=TEAM_COP, 0b00000010=TEAM_ROBBER, and 0b00000100=TEAM_CIV...
0b00000111 would be 7 (1+2+4), or the 3 teams gathered together
Thanks! So what is the correct way for the enum increasement?
Reply
#6

Quote:
Originally Posted by wups
Посмотреть сообщение
Thanks! So what is the correct way for the enum increasement?
The way it is displayed on the Wiki (how you have it here) is perfectly fine. Also, this is not new :P

I've never read or heard of a limit on enumerations in the Pawn documentation. I would assume the maximum amount you could store would be unlimited. However, I don't see how you would store all player inventory in one variable.
Reply
#7

Quote:
Originally Posted by Bakr
Посмотреть сообщение
The way it is displayed on the Wiki (how you have it here) is perfectly fine. Also, this is not new :P

I've never read or heard of a limit on enumerations in the Pawn documentation. I would assume the maximum amount you could store would be unlimited. However, I don't see how you would store all player inventory in one variable.
New for me ^^
The same way, the wiki stores player teams in one variable. No, I won't store stackable items, if that's what you had in mind. By one variable i meant one variable per player..
Reply
#8

Quote:
Originally Posted by wups
Посмотреть сообщение
New for me ^^
The same way, the wiki stores player teams in one variable. No, I won't store stackable items, if that's what you had in mind. By one variable i meant one variable per player..
Edit: Yes, I completely misunderstood, sorry.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)