Up to date
This page is up to date for Godot 4.0
.
If you still find outdated information, please open an issue.
bool¶
A built-in boolean type.
Description¶
A bool is always one of two values: true
or false
, similar to a switch that is either on or off. Booleans are used in programming for logic in condition statements.
Booleans can be directly used in if
and elif
statements. You don't need to add == true
or == false
:
if can_shoot:
launch_bullet()
if (canShoot)
{
launchBullet();
}
Many common methods and operations return bools, for example, shooting_cooldown <= 0.0
may evaluate to true
or false
depending on the number's value.
bools are usually used with the logical operators and
, or
, and not
to create complex conditions:
if bullets > 0 and not is_reloading:
launch_bullet()
if bullets == 0 or is_reloading:
play_clack_sound()
if (bullets > 0 && !isReloading)
{
launchBullet();
}
if (bullets == 0 || isReloading)
{
playClackSound();
}
Constructors¶
bool ( ) |
|
Operators¶
operator != ( bool right ) |
|
operator < ( bool right ) |
|
operator == ( bool right ) |
|
operator > ( bool right ) |
Constructor Descriptions¶
bool bool ( )
Constructs a default-initialized bool set to false
.
Constructs a bool as a copy of the given bool.
Cast a float value to a boolean value. This method will return false
if 0.0
is passed in, and true
for all other values.
Cast an int value to a boolean value. This method will return false
if 0
is passed in, and true
for all other values.
Operator Descriptions¶
bool operator != ( bool right )
Returns true
if two bools are different, i.e. one is true
and the other is false
.
bool operator < ( bool right )
Returns true
if the left operand is false
and the right operand is true
.
bool operator == ( bool right )
Returns true
if two bools are equal, i.e. both are true
or both are false
.
bool operator > ( bool right )
Returns true
if the left operand is true
and the right operand is false
.