Boolian variables - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Boolian variables (
/showthread.php?tid=258955)
Boolian variables -
nuriel8833 - 02.06.2011
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
AW: Boolian variables -
Nero_3D - 02.06.2011
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];
Re: Boolian variables -
Sergei - 02.06.2011
LocInfo[strlen(tmp)][AvailableTeleport] = false;
LocInfo[strlen(tmp)][AvailableTeleport] = true;
LocInfo[id][AvailableTeleport] = !!strval(Argument[7]);
And it's called boolean.
Re: Boolian variables -
Raimis_R - 02.06.2011
And not
But
Re: Boolian variables -
nuriel8833 - 02.06.2011
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
|
Thank you for noticing that
Re: Boolian variables -
nuriel8833 - 03.06.2011
Bump
Re: Boolian variables -
nuriel8833 - 04.06.2011
Bump 2
AW: Boolian variables -
Nero_3D - 04.06.2011
just use false / true, it wont cause any problems since the script auto converts it to 0 and 1
Re: Boolian variables -
Sergei - 04.06.2011
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.