How to use "Boolean"
#1

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 (:
Reply
#2

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

Only use "==" when comparing.
Reply
#3

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

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)
{

}
Reply
#5

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

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

? 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"));
Reply
#8

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


Forum Jump:


Users browsing this thread: 1 Guest(s)