SA-MP Forums Archive
How to use "Boolean" - 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)
+--- Thread: How to use "Boolean" (/showthread.php?tid=526441)



How to use "Boolean" - mrkiller90 - 17.07.2014

So my problem is that I saw in some tutorials people writing something like this " ? true : false ", I wanna know how to apply this in my code because I am simply writing " HouseInfo[i][hOwned] == false " and it's not working when I save it.

I just wanna know if the problem is on the boolean because not using that thing " ? true : false " or is in the saving system.

Help is appreciated, thanks (:


Re: How to use "Boolean" - PrivatioBoni - 17.07.2014

Assigning to true or false is just "= true;" or "= false;"

Only use "==" when comparing.


Re: How to use "Boolean" - mrkiller90 - 17.07.2014

oh yeah I'm sorry my bad, I know that but I wrote wrong in this post, thats not my problem


Re: How to use "Boolean" - Dignity - 17.07.2014

Quote:
Originally Posted by PrivatioBoni
Посмотреть сообщение
Assigning to true or false is just "= true;" or "= false;"

Only use "==" when comparing.
Or you can do it like this aswell:

pawn Код:
new bool: variable;

// Variable is true:
if(variable)
{

}


// Variable is false:
else if(!variable)
{

}



Re: How to use "Boolean" - PrivatioBoni - 17.07.2014

Might be the loop you've done before or the saving system.
Any errors?


Re: How to use "Boolean" - mrkiller90 - 17.07.2014

No, I got no errors at all (the bool is at the enum)


Re: How to use "Boolean" - paulommu - 17.07.2014

? true : false is called ternary operator.

It's a easy way to replace this:

pawn Код:
if(condition)
{
    var = value;
}
else
{
    var = anothervalue;
}
With this:

pawn Код:
var = (condition) ? value : anothervalue;
'?' = if the condition proceeds
':' = else

Some examples:

pawn Код:
new value = 5;
new bool: isfive = (value == 5) ? true : false;
pawn Код:
new string[] = "hello world";
new bool: isempty = (strlen(string)) ? false : true;
pawn Код:
new Float: value = 0.0;
print("The float value %s.", (value > 0.0) ? ("isn't null") : ("is null"));



Re: How to use "Boolean" - mrkiller90 - 17.07.2014

Oh Thanks a lot paulommu it's a perfect explanation that helped me a lot for real! (rep)