11.01.2013, 21:55
You may also add that you can define the increment and decrement of the enum values, like Slice did in his Tips & Tricks thread where he used Enums to create 32 flags into one single variable:
Notice that in the PlayerFlags enum, he has this tiny piece of code after the name of it:
This will tell the enum to set the next enum-data to the number equal to the previous enum-data shifted to the left.
Standard enums would have had this piece of code attached to it
But remember, as Slice mentioned in the quote above: The first value will be set to 0 unless you specify otherwise. So if you try using multiplication or division without specifying the value of the first enum-data, you will just get lots of 0's - which you don't want.
EDIT: Nice tutorial btw - +1
Quote:
Bit-flags in enums
Did you know that you can store 32 true/false values in one single variable? Not only do you save space, but you also get less clutter in your code. |
pawn Code:
:(<<= 1)
Standard enums would have had this piece of code attached to it
pawn Code:
:(++)
//or possibly :(+= 1)
EDIT: Nice tutorial btw - +1