mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-05 22:09:56 +03:00
Sync classref with current source
This commit is contained in:
@@ -14,7 +14,7 @@ Expression
|
||||
Brief Description
|
||||
-----------------
|
||||
|
||||
|
||||
A class that stores an expression you can execute.
|
||||
|
||||
Methods
|
||||
-------
|
||||
@@ -29,6 +29,31 @@ Methods
|
||||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`parse<class_Expression_parse>` **(** :ref:`String<class_String>` expression, :ref:`PoolStringArray<class_PoolStringArray>` input_names=PoolStringArray( ) **)** |
|
||||
+----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
An expression can be made of any arithmetic operation, built-in math function call, method call of a passed instance, or built-in type construction call.
|
||||
|
||||
An example expression text using the built-in math functions could be ``sqrt(pow(3,2) + pow(4,2))``.
|
||||
|
||||
In the following example we use a :ref:`LineEdit<class_LineEdit>` node to write our expression and show the result.
|
||||
|
||||
::
|
||||
|
||||
onready var expression = Expression.new()
|
||||
|
||||
func _ready():
|
||||
$LineEdit.connect("text_entered", self, "_on_text_entered")
|
||||
|
||||
func _on_text_entered(command):
|
||||
var error = expression.parse(command, [])
|
||||
if error != OK:
|
||||
print(get_error_text())
|
||||
return
|
||||
var result = expression.execute([], null, true)
|
||||
if not expression.has_execute_failed():
|
||||
$LineEdit.text = str(result)
|
||||
|
||||
Method Descriptions
|
||||
-------------------
|
||||
|
||||
@@ -36,15 +61,23 @@ Method Descriptions
|
||||
|
||||
- :ref:`Variant<class_Variant>` **execute** **(** :ref:`Array<class_Array>` inputs=[ ], :ref:`Object<class_Object>` base_instance=null, :ref:`bool<class_bool>` show_error=true **)**
|
||||
|
||||
Executes the expression that was previously parsed by :ref:`parse<class_Expression_parse>` and returns the result. Before you use the returned object, you should check if the method failed by calling :ref:`has_execute_failed<class_Expression_has_execute_failed>`.
|
||||
|
||||
.. _class_Expression_get_error_text:
|
||||
|
||||
- :ref:`String<class_String>` **get_error_text** **(** **)** const
|
||||
|
||||
Returns the error text if :ref:`parse<class_Expression_parse>` has failed.
|
||||
|
||||
.. _class_Expression_has_execute_failed:
|
||||
|
||||
- :ref:`bool<class_bool>` **has_execute_failed** **(** **)** const
|
||||
|
||||
Returns ``true`` if :ref:`execute<class_Expression_execute>` has failed.
|
||||
|
||||
.. _class_Expression_parse:
|
||||
|
||||
- :ref:`Error<enum_@GlobalScope_Error>` **parse** **(** :ref:`String<class_String>` expression, :ref:`PoolStringArray<class_PoolStringArray>` input_names=PoolStringArray( ) **)**
|
||||
|
||||
Parses the expression and returns a :ref:`Error<enum_@GlobalScope_Error>`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user