Re: Tips & Tricks -
Emmet_ - 19.12.2013
Quote:
Originally Posted by dipsnark
Did you test bit-flags? BitFlag_Get macro awlays returns zero.
|
The comment in the first post says:
pawn Code:
// Returns zero (false) if the flag isn't set.
So you have to use BigFlag_Set first.
Re: Tips & Tricks -
dipsnark - 19.12.2013
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:
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));
}
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.
AW: Re: Tips & Tricks -
xerox8521 - 25.01.2014
Quote:
Originally Posted by Y_Less
You can put "char" on any array where the highest value to be stored will be 255, and the lowest 0 (or -128 - 127).
|
Question how would you use char arrays on player variables which are created with an enum.
like:
pawn Code:
enum pInfo
{
pName[MAX_PLAYER_NAME],
pIP[16],
pInfected,
pDiedAsSurvivor,
pMuted,
pAdmin,
pLastTimeHit
}
new PlayerInfo[30][pInfo];
maybe like so ? new PlayerInfo[30][pInfo char];
Re: Tips & Tricks -
Patrick - 25.01.2014
I think you can not use
Char-Array in
2-3 Dimensional array
pawn Code:
error 051: invalid subscript, use "[ ]" operators on major dimensions
but you could do this inside an enumerator ( only arrays )
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);
}
Re: Tips & Tricks -
RenovanZ - 06.06.2014
Very nice! This will be used for my GM.
Re: Tips & Tricks -
Y_Less - 07.06.2014
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.
Re: Tips & Tricks -
Patrick - 07.06.2014
Quote:
Originally Posted by Y_Less
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.
|
This was posted 5 months ago

Anyways thanks for pointing that out.
Re: Tips & Tricks -
theYiin - 17.06.2015
Quote:
Originally Posted by Yashas
Its num args by the way..
|
right
Re: Tips & Tricks -
Yashas - 17.06.2015
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,
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
You can do lot of things with #emit
Re: Tips & Tricks -
theYiin - 18.06.2015
If you have boolean variable like
Code:
new isEventRunning;
instead of doing this
Code:
if(isEventRunning) {
isEventRunning = false;
// do stuff
}
else {
isEventRunning = true;
// do stuff
}
you can instead do this
Code:
if((isEventRunning = !isEventRunning)) {
// event is running
}
else {
// event isn't running
}
or
Code:
if((isEventRunning ^= 1)) {
// event is running
}
else {
/ event is not running
}
Re: Tips & Tricks -
Uberanwar - 02.04.2016
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?
Re: Tips & Tricks -
itsCody - 02.04.2016
Quote:
Originally Posted by Uberanwar
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?
|
if(!BitFlag_Get(g_PlayerFlags[playerid], Spawned))
Not sure about bits, but give that a try?
Re: Tips & Tricks -
darkdevil - 19.05.2016
Wow nice
Re: Tips & Tricks -
Sjn - 21.05.2016
Is it possible to use bit flags for float, strings and other arrays too? If so, can someone show an example? It looks interesting.
Re: Tips & Tricks -
PrO.GameR - 21.05.2016
Quote:
Originally Posted by Sjn
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.
Re: Tips & Tricks -
Sjn - 21.05.2016
Quote:
Originally Posted by PrO.GameR
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.
|
Alright, that pretty much makes sense. Thanks.
Re: Tips & Tricks -
Gammix - 13.12.2017
Quote:
Originally Posted by Logic_
Sorry for the bump, but shouldn't this
PHP код:
for(new i = strlen(string); i != EOS; i--)
be the most fastest string loop?
|
EOF is value 0 so you are stoping at index 1! Its 0 in c/c++.
Here, without the use of strlen:
PHP код:
for (new i; string[i] != EOF; i++) {
}
Re: Tips & Tricks -
Logic_ - 13.12.2017
Quote:
Originally Posted by Gammix
EOF is value 0 so you are stoping at index 1! Its 0 in c/c++.
Here, without the use of strlen:
PHP код:
for (new i; string[i] != EOF; i++) {
}
|
Yep right, I mis-typed my code
Re: Tips & Tricks -
Misiur - 14.12.2017
EOS is '\0', that is: 0. So, use the one you feel is right in the context.
Re: Tips & Tricks -
RoboN1X - 09.06.2018
I want to ask about bit flags on enum, why do you need a colon after the symbol name
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]
;
Can i just omit the colon like this?:
Код:
enum PlayerFlags (<<= 1)
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):
Код:
// 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
But if i omit the colon:
Код:
// 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);
I could also do this to give a player "random" flags:
Код:
g_PlayerFlags[playerid] = playerFlags:random(playerFlags);
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?
Код:
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);
Is it okay to do that? does that make differences? Of course i know it would overflow if i add more bits...