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.
Checking the stable version of the documentation...
bool
Un tipo booleano incorporado.
Descripción
El bool es un tipo Variant integrado que solo puede almacenar uno de dos valores: true o false. Puede imaginarlo como un interruptor que puede estar encendido o apagado, o como un dígito binario que puede ser 1 o 0.
Los booleanos pueden utilizarse directamente en if y otras sentencias condicionales:
var can_shoot = true
if can_shoot:
launch_bullet()
bool canShoot = true;
if (canShoot)
{
LaunchBullet();
}
Todos los operadores de comparación devuelven booleanos (==, >, <=, etc.). Como tal, no es necesario comparar los booleanos entre sí. No es necesario añadir == true o == false.
Los booleanos pueden combinarse con los operadores lógicos and, or, not para crear condiciones complejas:
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();
}
Nota: En los lenguajes de programación modernos, los operadores lógicos se evalúan en orden. Todas las condiciones restantes se omiten si su resultado no tuviera efecto en el valor final. Este concepto se conoce como evaluación de cortocircuito y puede ser útil para evitar la evaluación de condiciones costosas en algunos casos críticos para el rendimiento.
Nota: Por convención, los métodos y propiedades integrados que devuelven booleanos suelen definirse como preguntas de sí o no, adjetivos simples o similares (String.is_empty(), Node.can_process(), Camera2D.enabled, etc.).
Constructores
bool() |
|
Operadores
operator !=(right: bool) |
|
operator <(right: bool) |
|
operator ==(right: bool) |
|
operator >(right: bool) |
Descripciones de Constructores
Construye un bool establecido en false.
Construye un bool como una copia del bool dado.
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).
Casts an int value to a bool. Returns false if from is equal to 0, and true for all other values.
Descripciones de Operadores
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.