FuncRef.xml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="FuncRef" inherits="Reference" category="Core" version="3.1">
  3. <brief_description>
  4. Reference to a function in an object.
  5. </brief_description>
  6. <description>
  7. In GDScript, functions are not [i]first-class objects[/i]. This means it is impossible to store them directly as variables, return them from another function, or pass them as arguments.
  8. However, by creating a [code]FuncRef[/code] using the [method @GDScript.funcref] function, a reference to a function in a given object can be created, passed around and called.
  9. </description>
  10. <tutorials>
  11. </tutorials>
  12. <demos>
  13. </demos>
  14. <methods>
  15. <method name="call_func" qualifiers="vararg">
  16. <return type="Variant">
  17. </return>
  18. <description>
  19. Calls the referenced function previously set by [method set_function] or [method @GDScript.funcref].
  20. </description>
  21. </method>
  22. <method name="set_function">
  23. <return type="void">
  24. </return>
  25. <argument index="0" name="name" type="String">
  26. </argument>
  27. <description>
  28. The name of the referenced function to call on the object, without parentheses or any parameters.
  29. </description>
  30. </method>
  31. <method name="set_instance">
  32. <return type="void">
  33. </return>
  34. <argument index="0" name="instance" type="Object">
  35. </argument>
  36. <description>
  37. The object containing the referenced function. This object must be of a type actually inheriting from [Object], not a built-in type such as [int], [Vector2] or [Dictionary].
  38. </description>
  39. </method>
  40. </methods>
  41. <constants>
  42. </constants>
  43. </class>