Skip to content

Commit 971fe5a

Browse files
authored
Merge pull request #10613 from Vocco/expression-logical-operators
Document logical operator support in `Expression`
2 parents ea1b882 + 404a2bc commit 971fe5a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tutorials/scripting/evaluating_expressions.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Godot provides an :ref:`class_Expression` class you can use to evaluate expressi
88
An expression can be:
99

1010
- A mathematical expression such as ``(2 + 4) * 16/4.0``.
11+
- A boolean expression such as ``true && false``.
1112
- A built-in method call like ``deg_to_rad(90)``.
1213
- A method call on a user-provided script like ``update_health()``,
1314
if ``base_instance`` is set to a value other than ``null`` when calling
@@ -47,6 +48,12 @@ The following operators are available:
4748
| Remainder (``%``) | Returns the remainder of an integer division (modulo). |
4849
| | The result will always have the sign of the dividend. |
4950
+------------------------+-------------------------------------------------------------------------------------+
51+
| Conjunction (``&&``) | Returns the result of a boolean AND. |
52+
+------------------------+-------------------------------------------------------------------------------------+
53+
| Disjunction (``||``) | Returns the result of a boolean OR. |
54+
+------------------------+-------------------------------------------------------------------------------------+
55+
| Negation (``!``) | Returns the result of a boolean NOT. |
56+
+------------------------+-------------------------------------------------------------------------------------+
5057

5158
Spaces around operators are optional. Also, keep in mind the usual
5259
`order of operations <https://en.wikipedia.org/wiki/Order_of_operations>`__
@@ -141,6 +148,11 @@ The script below demonstrates what the Expression class is capable of::
141148

142149

143150
func _ready():
151+
# Constant boolean expression.
152+
evaluate("true && false")
153+
# Boolean expression with variables.
154+
evaluate("!(a && b)", ["a", "b"], [true, false])
155+
144156
# Constant mathexpression.
145157
evaluate("2 + 2")
146158
# Math expression with variables.
@@ -181,6 +193,8 @@ The script below demonstrates what the Expression class is capable of::
181193

182194
The output from the script will be::
183195

196+
false
197+
true
184198
4
185199
160
186200
1.5707963267949

0 commit comments

Comments
 (0)