class_expression.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Expression.xml.
  6. .. _class_Expression:
  7. Expression
  8. ==========
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. A class that stores an expression you can execute.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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.
  15. An example expression text using the built-in math functions could be ``sqrt(pow(3,2) + pow(4,2))``.
  16. In the following example we use a :ref:`LineEdit<class_LineEdit>` node to write our expression and show the result.
  17. ::
  18. onready var expression = Expression.new()
  19. func _ready():
  20. $LineEdit.connect("text_entered", self, "_on_text_entered")
  21. func _on_text_entered(command):
  22. var error = expression.parse(command, [])
  23. if error != OK:
  24. print(expression.get_error_text())
  25. return
  26. var result = expression.execute([], null, true)
  27. if not expression.has_execute_failed():
  28. $LineEdit.text = str(result)
  29. .. rst-class:: classref-reftable-group
  30. Methods
  31. -------
  32. .. table::
  33. :widths: auto
  34. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Variant<class_Variant>` | :ref:`execute<class_Expression_method_execute>` **(** :ref:`Array<class_Array>` inputs=[ ], :ref:`Object<class_Object>` base_instance=null, :ref:`bool<class_bool>` show_error=true **)** |
  36. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`String<class_String>` | :ref:`get_error_text<class_Expression_method_get_error_text>` **(** **)** |const| |
  38. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`has_execute_failed<class_Expression_method_has_execute_failed>` **(** **)** |const| |
  40. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`parse<class_Expression_method_parse>` **(** :ref:`String<class_String>` expression, :ref:`PoolStringArray<class_PoolStringArray>` input_names=PoolStringArray( ) **)** |
  42. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. .. rst-class:: classref-section-separator
  44. ----
  45. .. rst-class:: classref-descriptions-group
  46. Method Descriptions
  47. -------------------
  48. .. _class_Expression_method_execute:
  49. .. rst-class:: classref-method
  50. :ref:`Variant<class_Variant>` **execute** **(** :ref:`Array<class_Array>` inputs=[ ], :ref:`Object<class_Object>` base_instance=null, :ref:`bool<class_bool>` show_error=true **)**
  51. Executes the expression that was previously parsed by :ref:`parse<class_Expression_method_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_method_has_execute_failed>`.
  52. If you defined input variables in :ref:`parse<class_Expression_method_parse>`, you can specify their values in the inputs array, in the same order.
  53. .. rst-class:: classref-item-separator
  54. ----
  55. .. _class_Expression_method_get_error_text:
  56. .. rst-class:: classref-method
  57. :ref:`String<class_String>` **get_error_text** **(** **)** |const|
  58. Returns the error text if :ref:`parse<class_Expression_method_parse>` has failed.
  59. .. rst-class:: classref-item-separator
  60. ----
  61. .. _class_Expression_method_has_execute_failed:
  62. .. rst-class:: classref-method
  63. :ref:`bool<class_bool>` **has_execute_failed** **(** **)** |const|
  64. Returns ``true`` if :ref:`execute<class_Expression_method_execute>` has failed.
  65. .. rst-class:: classref-item-separator
  66. ----
  67. .. _class_Expression_method_parse:
  68. .. rst-class:: classref-method
  69. :ref:`Error<enum_@GlobalScope_Error>` **parse** **(** :ref:`String<class_String>` expression, :ref:`PoolStringArray<class_PoolStringArray>` input_names=PoolStringArray( ) **)**
  70. Parses the expression and returns an :ref:`Error<enum_@GlobalScope_Error>` code.
  71. You can optionally specify names of variables that may appear in the expression with ``input_names``, so that you can bind them when it gets executed.
  72. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  73. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  74. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  75. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`