19.12.2013, 21:28
Tips & Tricks
19.12.2013, 21:33
There is no BitFlag_Set but BitFlag_On and BitFlag_Off. And I set it to on/off then used BitFlag_Get but it only returns 0.
Test this code:
It not only returns 0 but the line with prefix '_B_' returns 2. And another returns 4(can buy property).
EDIT: OMFG I'm such a noob just realised I can check if it is set or not so don't have to check it's value...
Nice tut btw.
Test this code:
Code:
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)); }
EDIT: OMFG I'm such a noob just realised I can check if it is set or not so don't have to check it's value...
Nice tut btw.
25.01.2014, 22:20
Quote:
You can put "char" on any array where the highest value to be stored will be 255, and the lowest 0 (or -128 - 127).
|
like:
pawn Code:
enum pInfo
{
pName[MAX_PLAYER_NAME],
pIP[16],
pInfected,
pDiedAsSurvivor,
pMuted,
pAdmin,
pLastTimeHit
}
new PlayerInfo[30][pInfo];
25.01.2014, 23:09
I think you can not use Char-Array in 2-3 Dimensional array
but you could do this inside an enumerator ( only arrays )
pawn Code:
error 051: invalid subscript, use "[ ]" operators on major dimensions
pawn Code:
#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);
}
06.06.2014, 12:33
Very nice! This will be used for my GM.
07.06.2014, 17:59
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.
07.06.2014, 18:58
17.06.2015, 17:27
17.06.2015, 17:48
I think my post is going to get hidden in this thread.The newer replies will cover it up.
You can also do getargs using assembly by accessing each element on the stack.
For example,
You can do lot of things with #emit
You can also do getargs using assembly by accessing each element on the stack.
For example,
Code:
#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
18.06.2015, 15:28
If you have boolean variable like
instead of doing this
you can instead do this
or
Code:
new isEventRunning;
Code:
if(isEventRunning) { isEventRunning = false; // do stuff } else { isEventRunning = true; // do stuff }
Code:
if((isEventRunning = !isEventRunning)) { // event is running } else { // event isn't running }
Code:
if((isEventRunning ^= 1)) { // event is running } else { / event is not running }
02.04.2016, 05:17
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?
How do you check if Spawned is false?
02.04.2016, 05:23
Quote:
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? |
Not sure about bits, but give that a try?
19.05.2016, 11:18
Wow nice
21.05.2016, 07:21
Is it possible to use bit flags for float, strings and other arrays too? If so, can someone show an example? It looks interesting.
21.05.2016, 07:34
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.
21.05.2016, 09:59
13.12.2017, 20:33
Quote:
Sorry for the bump, but shouldn't this
PHP код:
|
Here, without the use of strlen:
PHP код:
for (new i; string[i] != EOF; i++) {
}
13.12.2017, 20:46
14.12.2017, 09:35
EOS is '\0', that is: 0. So, use the one you feel is right in the context.
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);
« Next Oldest | Next Newest »
Users browsing this thread: 2 Guest(s)