Bool in enum. -
antonio112 - 04.11.2011
Hello people. I'm working on a gamemode and I'm stuck at the moment. What's my problem? Let's say, for example I a player enum, in which I want to add a bool, for example Admin Duty:
pawn Код:
enum P_ENUM_DATA
{
pADuty // I want to change this to bool:pADuty
};
new pInfo[MAX_PLAYERS][P_ENUM_DATA];
Now, my question is how can I use / save / load that boolean? I'm using Y_INI.
On
OnPlayerDisconnect
pawn Код:
INI_WriteInt(File,"AdminDuty", P_DATA[playerid][pADuty]);
and of course, load function:
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("AdminDuty", P_DATA[playerid][pADuty]);
So, like I said, how can I convert the
pADuty integer to boolean? Thank you.
Re: Bool in enum. -
Vince - 05.11.2011
A bool is a weak tag in Pawn (read more about strong and weak tags in the manual), so it shouldn't be a problem if you just prefix it with
bool: tag. Although I must say that using bools in Pawn is quite useless because they consume the same memory as regular integer variables.
Re: Bool in enum. -
Kush - 05.11.2011
Boolean literals would be expressed the same way as an integer. Though, values 0 (false) and 1 (true) are only recognized as adjacent.
Re: Bool in enum. -
antonio112 - 05.11.2011
Quote:
Originally Posted by Vince
A bool is a weak tag in Pawn (read more about strong and weak tags in the manual), so it shouldn't be a problem if you just prefix it with bool: tag. Although I must say that using bools in Pawn is quite useless because they consume the same memory as regular integer variables.
|
Oh, they do consume the same memory as integers? Don't know why but I thought it consumes much lesser memory ... If that's the case, I won't complicated my enum with bools. Thank you for your answers.
Re: Bool in enum. -
steki. - 05.11.2011
Making it more easy: There's no difference between integers and booleans in pawn. They consume the same memory amount.
Re: Bool in enum. -
Lorenc_ - 05.11.2011
pawn Код:
new intTmp;
INI_Int("AdminDuty", intTmp);
P_DATA[playerid][pADuty] = !!intTmp;
Little conversion from int to bool.
Make the P_DATA pADuty a boolean!
edit:
pawn Код:
#define IntToBool(%1,%2) (%1=!!%2)
INI_Int("AdminDuty", IntToBool(strval(value), PlayerInfo[playerid][E_ADMINDUTY]));
Re: Bool in enum. -
Kush - 05.11.2011
Quote:
Originally Posted by Stewie`
Making it more easy: There's no difference between integers and booleans in pawn. They consume the same memory amount.
|
Pardon me? Boolean uses less memory to process, hence the reason why when depicting whether values of true and false, you would use this instead of integers.
Re: Bool in enum. -
antonio112 - 05.11.2011
Alright ... if that's true, I still can't get it work. Here's what I got so far:
pawn Код:
enum P_ENUM_DATA
{
bool:pADuty
};
new P_DATA[MAX_PLAYERS][P_ENUM_DATA];
And now, on LoadPlayerData:
pawn Код:
INI_Int("AdminDuty", P_DATA[playerid][pADuty]);
I get the next warning:
(795) : warning 213: tag mismatch
How can I 'convert' it to boolean?
Also,
OnPlayerDisconnect I have this:
pawn Код:
INI_WriteInt(File,"AdminDuty", P_DATA[playerid][pADuty]);
And I get no warnings or something and I'm just wondering, will it work? I'll give it a try anyway.
Re: Bool in enum. -
Lorenc_ - 05.11.2011
Quote:
Originally Posted by Lorenc_
pawn Код:
new intTmp; INI_Int("AdminDuty", intTmp); P_DATA[playerid][pADuty] = !!intTmp;
Little conversion from int to bool.
Make the P_DATA pADuty a boolean!
edit:
pawn Код:
#define IntToBool(%1,%2) (%1=!!%2)
INI_Int("AdminDuty", IntToBool(strval(value), PlayerInfo[playerid][E_ADMINDUTY]));
|
I have your solution, whats the point of ignoring it?
Re: Bool in enum. -
antonio112 - 05.11.2011
Quote:
Originally Posted by Lorenc_
I have your solution, whats the point of ignoring it?
|
It's not that I'm ignoring your solution, I'm trying to understand it and see how it works. Tried what you said and I get the next errors:
Quote:
(797) : error 022: must be lvalue (non-constant)
(797) : warning 215: expression has no effect
(797) : error 001: expected token: ";", but found ")"
(797) : error 029: invalid expression, assumed zero
(797) : fatal error 107: too many error messages on one line
|
Line 797:
INI_Int("AdminDuty", IntToBool(strval(value), P_DATA[playerid][pADuty]));
ps: Tested it without your solution and it seems to work well, even if I get that warning, about tag mismatch. Now I need to get rid of that warning.