Boolian variables
#1

Hello everyone.
I have a problem with setting boolian variables in a dini file.
I have this:
pawn Код:
enum locinfo
{
    LocNumber,
    Float:LocX,
    Float:LocY,
    Float:LocZ,
    Float:LocA,
    LocInterior,
    LocCreator[MAX_PLAYER_NAME],
    Bool:AvailableTeleport,
}
And whenever I use this;
pawn Код:
LocInfo[strlen(tmp)][AvailableTeleport] = 0;
or this:
pawn Код:
LocInfo[strlen(tmp)][AvailableTeleport] = 1;
I get a tag mismatch error.
But I don't know what will be saved in the file incase I will change the 1 and 0 to true and false.
+Which strval do I use to boolian arguments? for example:
pawn Код:
LocInfo[id][AvailableTeleport] = strval(Argument[7]);
Please help
Thanks
Reply
#2

if you convert true to a number it will be 1
if you convert false to a number it will be 0

if you convert an integer to boolean everything not 0 will be true and 0 will be false

If you save an boolean it will save it was 1 or 0
And than if you load the number you will get 1 or 0
Just put a bool: before it to convert it back again

pawn Код:
LocInfo[id][AvailableTeleport] = bool: strval(Argument[7]);
or the better methode, we know that argument[7] is only 1 or 0, we could do

pawn Код:
LocInfo[id][AvailableTeleport] = (Argument[7][0] == '1');
or like that, I think thats the easiest check from all

pawn Код:
LocInfo[id][AvailableTeleport] = bool: Argument[7][0];
Reply
#3

LocInfo[strlen(tmp)][AvailableTeleport] = false;
LocInfo[strlen(tmp)][AvailableTeleport] = true;

LocInfo[id][AvailableTeleport] = !!strval(Argument[7]);

And it's called boolean.
Reply
#4

And not
pawn Код:
Bool:AvailableTeleport
But
pawn Код:
bool:AvailableTeleport
Reply
#5

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
if you convert true to a number it will be 1
if you convert false to a number it will be 0

if you convert an integer to boolean everything not 0 will be true and 0 will be false

If you save an boolean it will save it was 1 or 0
And than if you load the number you will get 1 or 0
Just put a bool: before it to convert it back again

pawn Код:
LocInfo[id][AvailableTeleport] = bool: strval(Argument[7]);
or the better methode, we know that argument[7] is only 1 or 0, we could do

pawn Код:
LocInfo[id][AvailableTeleport] = (Argument[7][0] == '1');
or like that, I think thats the easiest check from all

pawn Код:
LocInfo[id][AvailableTeleport] = bool: Argument[7][0];
Okay,thank you very much
But how will it solve my errors? If I do 0 and 1 I get warnings and if I do true/false it will cause troubles reading from the file.

Quote:
Originally Posted by Sergei
Посмотреть сообщение
LocInfo[strlen(tmp)][AvailableTeleport] = false;
LocInfo[strlen(tmp)][AvailableTeleport] = true;

LocInfo[id][AvailableTeleport] = !!strval(Argument[7]);

And it's called boolean.
I know I can also use true and false,But I'm afraid it will cause troubles while it uploads&saves the variable in the file.

Quote:
Originally Posted by Raimis_R
Посмотреть сообщение
And not
pawn Код:
Bool:AvailableTeleport
But
pawn Код:
bool:AvailableTeleport
Thank you for noticing that
Reply
#6

Bump
Reply
#7

Bump 2
Reply
#8

just use false / true, it wont cause any problems since the script auto converts it to 0 and 1
Reply
#9

Quote:
Originally Posted by Montserrat
Посмотреть сообщение
I know I can also use true and false,But I'm afraid it will cause troubles while it uploads&saves the variable in the file.
Not that you can, you must use it. And you know nothing, otherwise you had't created this thread.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)