class_bool.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/doc/classes/bool.xml.
  6. .. _class_bool:
  7. bool
  8. ====
  9. A built-in boolean type.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. A **bool** is always one of two values: ``true`` or ``false``, similar to a switch that is either on or off. Booleans are used in programming for logic in condition statements.
  14. Booleans can be directly used in ``if`` and ``elif`` statements. You don't need to add ``== true`` or ``== false``:
  15. .. tabs::
  16. .. code-tab:: gdscript
  17. if can_shoot:
  18. launch_bullet()
  19. .. code-tab:: csharp
  20. if (canShoot)
  21. {
  22. launchBullet();
  23. }
  24. Many common methods and operations return **bool**\ s, for example, ``shooting_cooldown <= 0.0`` may evaluate to ``true`` or ``false`` depending on the number's value.
  25. \ **bool**\ s are usually used with the logical operators ``and``, ``or``, and ``not`` to create complex conditions:
  26. .. tabs::
  27. .. code-tab:: gdscript
  28. if bullets > 0 and not is_reloading:
  29. launch_bullet()
  30. if bullets == 0 or is_reloading:
  31. play_clack_sound()
  32. .. code-tab:: csharp
  33. if (bullets > 0 && !isReloading)
  34. {
  35. launchBullet();
  36. }
  37. if (bullets == 0 || isReloading)
  38. {
  39. playClackSound();
  40. }
  41. .. rst-class:: classref-reftable-group
  42. Constructors
  43. ------------
  44. .. table::
  45. :widths: auto
  46. +-------------------------+-------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`bool<class_bool_constructor_bool>` **(** **)** |
  48. +-------------------------+-------------------------------------------------------------------------------------+
  49. | :ref:`bool<class_bool>` | :ref:`bool<class_bool_constructor_bool>` **(** :ref:`bool<class_bool>` from **)** |
  50. +-------------------------+-------------------------------------------------------------------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`bool<class_bool_constructor_bool>` **(** :ref:`float<class_float>` from **)** |
  52. +-------------------------+-------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`bool<class_bool_constructor_bool>` **(** :ref:`int<class_int>` from **)** |
  54. +-------------------------+-------------------------------------------------------------------------------------+
  55. .. rst-class:: classref-reftable-group
  56. Operators
  57. ---------
  58. .. table::
  59. :widths: auto
  60. +-------------------------+--------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`operator !=<class_bool_operator_neq_bool>` **(** :ref:`bool<class_bool>` right **)** |
  62. +-------------------------+--------------------------------------------------------------------------------------------+
  63. | :ref:`bool<class_bool>` | :ref:`operator \<<class_bool_operator_lt_bool>` **(** :ref:`bool<class_bool>` right **)** |
  64. +-------------------------+--------------------------------------------------------------------------------------------+
  65. | :ref:`bool<class_bool>` | :ref:`operator ==<class_bool_operator_eq_bool>` **(** :ref:`bool<class_bool>` right **)** |
  66. +-------------------------+--------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`operator ><class_bool_operator_gt_bool>` **(** :ref:`bool<class_bool>` right **)** |
  68. +-------------------------+--------------------------------------------------------------------------------------------+
  69. .. rst-class:: classref-section-separator
  70. ----
  71. .. rst-class:: classref-descriptions-group
  72. Constructor Descriptions
  73. ------------------------
  74. .. _class_bool_constructor_bool:
  75. .. rst-class:: classref-constructor
  76. :ref:`bool<class_bool>` **bool** **(** **)**
  77. Constructs a default-initialized **bool** set to ``false``.
  78. .. rst-class:: classref-item-separator
  79. ----
  80. .. rst-class:: classref-constructor
  81. :ref:`bool<class_bool>` **bool** **(** :ref:`bool<class_bool>` from **)**
  82. Constructs a **bool** as a copy of the given **bool**.
  83. .. rst-class:: classref-item-separator
  84. ----
  85. .. rst-class:: classref-constructor
  86. :ref:`bool<class_bool>` **bool** **(** :ref:`float<class_float>` from **)**
  87. Cast a :ref:`float<class_float>` value to a boolean value. This method will return ``false`` if ``0.0`` is passed in, and ``true`` for all other values.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. rst-class:: classref-constructor
  91. :ref:`bool<class_bool>` **bool** **(** :ref:`int<class_int>` from **)**
  92. Cast an :ref:`int<class_int>` value to a boolean value. This method will return ``false`` if ``0`` is passed in, and ``true`` for all other values.
  93. .. rst-class:: classref-section-separator
  94. ----
  95. .. rst-class:: classref-descriptions-group
  96. Operator Descriptions
  97. ---------------------
  98. .. _class_bool_operator_neq_bool:
  99. .. rst-class:: classref-operator
  100. :ref:`bool<class_bool>` **operator !=** **(** :ref:`bool<class_bool>` right **)**
  101. Returns ``true`` if two bools are different, i.e. one is ``true`` and the other is ``false``.
  102. .. rst-class:: classref-item-separator
  103. ----
  104. .. _class_bool_operator_lt_bool:
  105. .. rst-class:: classref-operator
  106. :ref:`bool<class_bool>` **operator <** **(** :ref:`bool<class_bool>` right **)**
  107. Returns ``true`` if the left operand is ``false`` and the right operand is ``true``.
  108. .. rst-class:: classref-item-separator
  109. ----
  110. .. _class_bool_operator_eq_bool:
  111. .. rst-class:: classref-operator
  112. :ref:`bool<class_bool>` **operator ==** **(** :ref:`bool<class_bool>` right **)**
  113. Returns ``true`` if two bools are equal, i.e. both are ``true`` or both are ``false``.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_bool_operator_gt_bool:
  117. .. rst-class:: classref-operator
  118. :ref:`bool<class_bool>` **operator >** **(** :ref:`bool<class_bool>` right **)**
  119. Returns ``true`` if the left operand is ``true`` and the right operand is ``false``.
  120. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  121. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  122. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  123. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  124. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  125. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`