瀏覽代碼

Document logical operator support in `Expression`

Vojtech Krajnansky 5 月之前
父節點
當前提交
404a2bc96e
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      tutorials/scripting/evaluating_expressions.rst

+ 14 - 0
tutorials/scripting/evaluating_expressions.rst

@@ -8,6 +8,7 @@ Godot provides an :ref:`class_Expression` class you can use to evaluate expressi
 An expression can be:
 
 - A mathematical expression such as ``(2 + 4) * 16/4.0``.
+- A boolean expression such as ``true && false``.
 - A built-in method call like ``deg_to_rad(90)``.
 - A method call on a user-provided script like ``update_health()``,
   if ``base_instance`` is set to a value other than ``null`` when calling
@@ -47,6 +48,12 @@ The following operators are available:
 | Remainder (``%``)      | Returns the remainder of an integer division (modulo).                              |
 |                        | The result will always have the sign of the dividend.                               |
 +------------------------+-------------------------------------------------------------------------------------+
+| Conjunction (``&&``)   | Returns the result of a boolean AND.                                                |
++------------------------+-------------------------------------------------------------------------------------+
+| Disjunction (``||``)   | Returns the result of a boolean OR.                                                 |
++------------------------+-------------------------------------------------------------------------------------+
+| Negation (``!``)       | Returns the result of a boolean NOT.                                                |
++------------------------+-------------------------------------------------------------------------------------+
 
 Spaces around operators are optional. Also, keep in mind the usual
 `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::
 
 
     func _ready():
+        # Constant boolean expression.
+        evaluate("true && false")
+        # Boolean expression with variables.
+        evaluate("!(a && b)", ["a", "b"], [true, false])
+
         # Constant mathexpression.
         evaluate("2 + 2")
         # Math expression with variables.
@@ -181,6 +193,8 @@ The script below demonstrates what the Expression class is capable of::
 
 The output from the script will be::
 
+    false
+    true
     4
     160
     1.5707963267949