Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

bool

Un tipo booleano integrato.

Descrizione

Il bool è un tipo Variant integrato che può memorizzare solo uno dei due valori: true o false. Puoi immaginarlo come un interruttore che può essere acceso o spento, o come una cifra binaria che può essere 1 o 0.

I booleani possono essere utilizzati direttamente in if e in altre istruzioni condizionali:

var can_shoot = true
if can_shoot:
    launch_bullet()

Tutti gli operatori di confronto restituiscono valori booleani (==, >, <=, ecc.). Pertanto, non è necessario confrontare i booleani stessi. Non è necessario aggiungere == true o == false.

I booleani possono essere combinati con gli operatori logici and, or, not per creare condizioni complesse:

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

if bullets == 0 or is_reloading():
    play_clack_sound()

Nota: Nei linguaggi di programmazione moderni, gli operatori logici sono valutati in ordine. Tutte le condizioni restanti sono saltate se il loro risultato non avrebbe alcun effetto sul valore finale. Questo concetto è noto come valutazione a corto circuito e può essere utile per evitare di valutare condizioni costose in alcuni casi critici per le prestazioni.

Nota: Per convenzione, i metodi e le proprietà integrate che restituiscono booleani sono generalmente definiti come domande sì-no, singoli aggettivi, o simili (String.is_empty(), Node.can_process(), Camera2D.enabled, ecc.).

Costruttori

bool

bool()

bool

bool(from: bool)

bool

bool(from: float)

bool

bool(from: int)

Operatori

bool

operator !=(right: bool)

bool

operator <(right: bool)

bool

operator ==(right: bool)

bool

operator >(right: bool)


Descrizioni dei costruttori

bool bool() 🔗

Costruisce un bool impostato su false.


bool bool(from: bool)

Costruisce un bool come copia del bool specificato.


bool bool(from: float)

Casts a float value to a bool. Returns false if from is equal to 0.0 (including -0.0), and true for all other values (including @GDScript.INF and @GDScript.NAN).


bool bool(from: int)

Casts an int value to a bool. Returns false if from is equal to 0, and true for all other values.


Descrizioni degli operatori

bool operator !=(right: bool) 🔗

Returns true if one bool is true and the other bool is false. Equivalent to logical XOR (NEQ).


bool operator <(right: bool) 🔗

Returns true if the left bool is false and right is true.


bool operator ==(right: bool) 🔗

Returns true if both bools are true, or if both bools are false. Equivalent to logical XNOR (EQ).


bool operator >(right: bool) 🔗

Returns true if the left bool is true and right is false.