bool

A built-in boolean type.

Description

Thebool is a built-inVariant type that may only store one of two values:true orfalse. 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 inif, and other conditional statements:

varcan_shoot=trueifcan_shoot:launch_bullet()

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 operatorsand,or,not to create complex conditions:

ifbullets>0andnotis_reloading():launch_bullet()ifbullets==0oris_reloading():play_clack_sound()

Note: In modern programming languages, logical operators are evaluated in order. All remaining conditions are skipped if their result would have no effect on the final value. This concept is known asshort-circuit evaluation and can be useful to avoid evaluating expensive conditions in some performance-critical cases.

Note: By convention, built-in methods and properties that return booleans are usually defined as yes-no questions, single adjectives, or similar (String.is_empty(),Node.can_process(),Camera2D.enabled, etc.).

Constructors

bool

bool()

bool

bool(from:bool)

bool

bool(from:float)

bool

bool(from:int)

Operators

bool

operator !=(right:bool)

bool

operator <(right:bool)

bool

operator ==(right:bool)

bool

operator >(right:bool)


Constructor Descriptions

boolbool()🔗

Constructs abool set tofalse.


boolbool(from:bool)

Constructs abool as a copy of the givenbool.


boolbool(from:float)

Cast afloat value to a boolean value. Returnsfalse iffrom is equal to0.0 (including-0.0), andtrue for all other values (including@GDScript.INF and@GDScript.NAN).


boolbool(from:int)

Cast anint value to a boolean value. Returnsfalse iffrom is equal to0, andtrue for all other values.


Operator Descriptions

booloperator !=(right:bool)🔗

Returnstrue if the two booleans are not equal. That is, one istrue and the other isfalse. This operation can be seen as a logical XOR.


booloperator <(right:bool)🔗

Returnstrue if the left operand isfalse and the right operand istrue.


booloperator ==(right:bool)🔗

Returnstrue if the two booleans are equal. That is, both aretrue or both arefalse. This operation can be seen as a logical EQ or XNOR.


booloperator >(right:bool)🔗

Returnstrue if the left operand istrue and the right operand isfalse.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.