Bool in enum.
#1

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.
Reply
#2

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.
Reply
#3

Boolean literals would be expressed the same way as an integer. Though, values 0 (false) and 1 (true) are only recognized as adjacent.
Reply
#4

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.
Reply
#5

Making it more easy: There's no difference between integers and booleans in pawn. They consume the same memory amount.
Reply
#6

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]));
Reply
#7

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.
Reply
#8

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.
Reply
#9

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?
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)