:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/bool.xml. .. _class_bool: bool ==== A built-in boolean type. .. rst-class:: classref-introduction-group Description ----------- The **bool** is a built-in :ref:`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: .. tabs:: .. code-tab:: gdscript var can_shoot = true if can_shoot: launch_bullet() .. code-tab:: csharp bool canShoot = true; if (canShoot) { LaunchBullet(); } 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: .. tabs:: .. code-tab:: gdscript if bullets > 0 and not is_reloading(): launch_bullet() if bullets == 0 or is_reloading(): play_clack_sound() .. code-tab:: csharp if (bullets > 0 && !IsReloading()) { LaunchBullet(); } if (bullets == 0 || IsReloading()) { PlayClackSound(); } \ **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 (:ref:`String.is_empty()`, :ref:`Node.can_process()`, :ref:`Camera2D.enabled`, etc.). .. rst-class:: classref-reftable-group Constructors ------------ .. table:: :widths: auto +-------------------------+----------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`bool`\ (\ ) | +-------------------------+----------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`bool`\ (\ from\: :ref:`bool`\ ) | +-------------------------+----------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`bool`\ (\ from\: :ref:`float`\ ) | +-------------------------+----------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`bool`\ (\ from\: :ref:`int`\ ) | +-------------------------+----------------------------------------------------------------------------------+ .. rst-class:: classref-reftable-group Operators --------- .. table:: :widths: auto +-------------------------+-----------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator !=`\ (\ right\: :ref:`bool`\ ) | +-------------------------+-----------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator \<`\ (\ right\: :ref:`bool`\ ) | +-------------------------+-----------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator ==`\ (\ right\: :ref:`bool`\ ) | +-------------------------+-----------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator >`\ (\ right\: :ref:`bool`\ ) | +-------------------------+-----------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Constructor Descriptions ------------------------ .. _class_bool_constructor_bool: .. rst-class:: classref-constructor :ref:`bool` **bool**\ (\ ) :ref:`🔗` Constructs a **bool** set to ``false``. .. rst-class:: classref-item-separator ---- .. rst-class:: classref-constructor :ref:`bool` **bool**\ (\ from\: :ref:`bool`\ ) Constructs a **bool** as a copy of the given **bool**. .. rst-class:: classref-item-separator ---- .. rst-class:: classref-constructor :ref:`bool` **bool**\ (\ from\: :ref:`float`\ ) Cast a :ref:`float` value to a boolean value. Returns ``false`` if ``from`` is equal to ``0.0`` (including ``-0.0``), and ``true`` for all other values (including :ref:`@GDScript.INF` and :ref:`@GDScript.NAN`). .. rst-class:: classref-item-separator ---- .. rst-class:: classref-constructor :ref:`bool` **bool**\ (\ from\: :ref:`int`\ ) Cast an :ref:`int` value to a boolean value. Returns ``false`` if ``from`` is equal to ``0``, and ``true`` for all other values. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Operator Descriptions --------------------- .. _class_bool_operator_neq_bool: .. rst-class:: classref-operator :ref:`bool` **operator !=**\ (\ right\: :ref:`bool`\ ) :ref:`🔗` Returns ``true`` if the two booleans are not equal. That is, one is ``true`` and the other is ``false``. This operation can be seen as a logical XOR. .. rst-class:: classref-item-separator ---- .. _class_bool_operator_lt_bool: .. rst-class:: classref-operator :ref:`bool` **operator <**\ (\ right\: :ref:`bool`\ ) :ref:`🔗` Returns ``true`` if the left operand is ``false`` and the right operand is ``true``. .. rst-class:: classref-item-separator ---- .. _class_bool_operator_eq_bool: .. rst-class:: classref-operator :ref:`bool` **operator ==**\ (\ right\: :ref:`bool`\ ) :ref:`🔗` Returns ``true`` if the two booleans are equal. That is, both are ``true`` or both are ``false``. This operation can be seen as a logical EQ or XNOR. .. rst-class:: classref-item-separator ---- .. _class_bool_operator_gt_bool: .. rst-class:: classref-operator :ref:`bool` **operator >**\ (\ right\: :ref:`bool`\ ) :ref:`🔗` Returns ``true`` if the left operand is ``true`` and the right operand is ``false``. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)` .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)` .. |void| replace:: :abbr:`void (No return value.)`