The bool is a built-in Variant type that may only store one of two values: true
or false
. You can imagine it as a switch that can be either turned on or off, or as a binary digit that can either be 1 or 0.
Booleans can be directly used in if
, and other conditional statements:
All comparison operators return booleans (==
, >
, <=
, etc.). As such, it is not necessary to compare booleans themselves. You do not need to add == true
or == false
.
Booleans can be combined with the logical operators and
, or
, not
to create complex conditions:
Constructs a bool set to false
.
Constructs a bool as a copy of the given bool.
Cast a float value to a boolean value. Returns false
if from
is equal to 0.0
(including -0.0
), and true
for all other values (including @GDScript.INF and @GDScript.NAN).
Cast an int value to a boolean value. Returns false
if from
is equal to 0
, and true
for all other values.
Returns true
if the two booleans are not equal. That is, one is true
and the other is false
. This operation can be seen as a logical XOR.
Returns true
if the left operand is false
and the right operand is true
.
Returns true
if the two booleans are equal. That is, both are true
or both are false
. This operation can be seen as a logical EQ or XNOR.
Returns true
if the left operand is true
and the right operand is false
.