bool

Un tipo booleano incorporado.

Descripción

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:

var can_shoot = true
if can_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 operators and, or, not to create complex conditions:

if bullets > 0 and not is_reloading():
    launch_bullet()

if bullets == 0 or is_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 as short-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.).

Constructores

bool

bool()

bool

bool(from: bool)

bool

bool(from: float)

bool

bool(from: int)

Operadores

bool

operator !=(right: bool)

bool

operator <(right: bool)

bool

operator ==(right: bool)

bool

operator >(right: bool)


Descripciones de Constructores

bool bool() 🔗

Construye un bool establecido en false.


bool bool(from: bool)

Construye un bool como una copia del bool dado.


bool bool(from: float)

Convierte un valor float a un valor booleano. Devuelve false si from es igual a 0.0 (incluyendo -0.0), y true para todos los demás valores (incluyendo @GDScript.INF y @GDScript.NAN).


bool bool(from: int)

Convierte un valor int a un valor booleano. Devuelve false si from es igual a 0, y true para todos los demás valores.


Descripciones de Operadores

bool operator !=(right: bool) 🔗

Devuelve true si los dos booleanos no son iguales. Es decir, uno es true y el otro es false. Esta operación puede verse como un XOR lógico.


bool operator <(right: bool) 🔗

Devuelve true si el operando izquierdo es false y el operando derecho es true.


bool operator ==(right: bool) 🔗

Devuelve true si los dos booleanos son iguales. Es decir, ambos son true o ambos son false. Esta operación puede verse como un EQ o XNOR lógico.


bool operator >(right: bool) 🔗

Devuelve true si el operando izquierdo es true y el operando derecho es false.