// Returns zero (false) if the flag isn't set.
g_PlayerFlags[0] = PlayerFlags:0;
BitFlag_On(g_PlayerFlags[0], PLAYER_IS_LOGGED_IN);
printf("___ %i", BitFlag_Get(g_PlayerFlags[0], PLAYER_IS_LOGGED_IN));
BitFlag_Off(g_PlayerFlags[0], PLAYER_IS_LOGGED_IN);
printf("__ %i", BitFlag_Get(g_PlayerFlags[0], PLAYER_IS_LOGGED_IN));
printf("_S_%i", BitFlag_Get(g_PlayerFlags[0], PLAYER_HAS_GANG));
BitFlag_On(g_PlayerFlags[0], PLAYER_HAS_GANG);
printf("_B_%i", BitFlag_Get(g_PlayerFlags[0], PLAYER_HAS_GANG));
BitFlag_Off(g_PlayerFlags[0], PLAYER_HAS_GANG);
printf("_C_%i", BitFlag_Get(g_PlayerFlags[0], PLAYER_HAS_GANG));
}
|
You can put "char" on any array where the highest value to be stored will be 255, and the lowest 0 (or -128 - 127).
|
enum pInfo
{
pName[MAX_PLAYER_NAME],
pIP[16],
pInfected,
pDiedAsSurvivor,
pMuted,
pAdmin,
pLastTimeHit
}
new PlayerInfo[30][pInfo];
error 051: invalid subscript, use "[ ]" operators on major dimensions
#if (defined MAX_PLAYERS)
#undef MAX_PLAYERS
#define MAX_PLAYERS (30)
#endif
enum pInfo
{
pName[ MAX_PLAYER_NAME char]
}
new PlayerInfo[MAX_PLAYERS][pInfo];
public OnPlayerConnect(playerid)
{
return GetPlayerName(playerid, PlayerInfo[playerid]{pName}, MAX_PLAYER_NAME);
}
|
Patrick_: You can, you are just using it on the wrong dimension. However, things with the same syntax as arrays inside enums, often referred to as arrays by people, are not.
|
Anyways thanks for pointing that out.
#emit LOAD.S 16 //Give the location (stack) of the argument in bytes #emit LOAD.I //Get value stored from address #emit STOR.pri YOUR_VARIABLE_NAME //Will copy the argument to the variable
new isEventRunning;
if(isEventRunning) {
isEventRunning = false;
// do stuff
}
else {
isEventRunning = true;
// do stuff
}
if((isEventRunning = !isEventRunning)) {
// event is running
}
else {
// event isn't running
}
if((isEventRunning ^= 1)) {
// event is running
}
else {
/ event is not running
}
|
if(BitFlag_Get(g_PlayerFlags[playerid], Spawned)) return SendClientMessage(playerid,COLOR_ERROR,"{FB0000}ER ROR: {FFFFFF}You must be alive and spawned.");
How do you check if Spawned is false? |
|
Is it possible to use bit flags for float, strings and other arrays too? If so, can someone show an example? It looks interesting.
|
|
Bit flags are actually 1 integer, but each bit would indicate a different thing, 1 character of a string needs 4 byte (or 1 if packed), so no, bits are only for booleans (0 or 1) and don't make sense for others.
|
|
Sorry for the bump, but shouldn't this
PHP код:
|
for (new i; string[i] != EOF; i++) {
}
|
EOF is value 0 so you are stoping at index 1! Its 0 in c/c++.
Here, without the use of strlen: PHP код:
|
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)
// 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);
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);