09.06.2018, 09:56
(
Последний раз редактировалось RoboN1X; 09.06.2018 в 10:46.
)
I want to ask about bit flags on enum, why do you need a colon after the symbol name
PlayerFlags:(<<= 1)
Can i just omit the colon like this?:
will it affects/changes how it works?
There are reason i want to do this, one is to know the max size of enum (or whatever it is called):
But if i omit the colon:
I could also do this to give a player "random" flags:
Note that i know i could just use cellmax in case i have full 32 bits in the enum.
I just want to know the difference between this and in wiki
Also i want to know that if it's possible to have the bitflags enum on packed "char-array" in case i only need 8 bits instead of 32?
Is it okay to do that? does that make differences? Of course i know it would overflow if i add more bits...
PlayerFlags:(<<= 1)
Код:
enum PlayerFlags:(<<= 1) { // It's important that you don't forget to put "= 1" on the first flag. If you don't, all flags will be 0. PLAYER_IS_LOGGED_IN = 1, // 0b00000000000000000000000000000001 PLAYER_HAS_GANG, // 0b00000000000000000000000000000010 // ... }; new // Create an array with the same tag as the enum PlayerFlags:g_PlayerFlags[MAX_PLAYERS] ;
Код:
enum PlayerFlags (<<= 1)
There are reason i want to do this, one is to know the max size of enum (or whatever it is called):
Код:
// If use this enum PlayerFlags: (<<= 1) // These will give errors: printf("enum max = %i", PlayerFlags); // undefined symbol printf("enum max = %i", PlayerFlags:); // invalid expression printf("enum max = %i", sizeof PlayerFlags); // i know this is not correct way
Код:
// No colon after symbol name enum playerFlags (<<= 1) // i weakened/renamed the symbol name to avoid tag mismatch // This works fine printf("enum max = %i", playerFlags);
Код:
g_PlayerFlags[playerid] = playerFlags:random(playerFlags);
I just want to know the difference between this and in wiki
Also i want to know that if it's possible to have the bitflags enum on packed "char-array" in case i only need 8 bits instead of 32?
Код:
enum PlayerFlags:(<<= 1) { // It's important that you don't forget to put "= 1" on the first flag. If you don't, all flags will be 0. PLAYER_BLABLA_1 = 1, // 00000001 PLAYER_BLABLA_2, // 00000010 PLAYER_BLABLA_3, // 00000100 PLAYER_BLABLA_4, // 00001000 PLAYER_BLABLA_5, // 00010000 PLAYER_BLABLA_6, // 00100000 PLAYER_BLABLA_7, // 01000000 PLAYER_BLABLA_8 // 10000000 }; // Create an array with the same tag as the enum (packed) new PlayerFlags:g_PlayerFlags[MAX_PLAYERS char]; // Use case BitFlag_On(g_PlayerFlags{playerid}, PLAYER_BLABLA_8);