class_script.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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/Script.xml.
  6. .. _class_Script:
  7. Script
  8. ======
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`CSharpScript<class_CSharpScript>`, :ref:`GDScript<class_GDScript>`, :ref:`NativeScript<class_NativeScript>`, :ref:`PluginScript<class_PluginScript>`, :ref:`VisualScript<class_VisualScript>`
  11. A class stored as a resource.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. A class stored as a resource. A script extends the functionality of all objects that instance it.
  16. The ``new`` method of a script subclass creates a new instance. :ref:`Object.set_script<class_Object_method_set_script>` extends an existing object, if that object's class matches one of the script's base classes.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`../tutorials/scripting/index`
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +-----------------------------+-------------------------------------------------------+
  27. | :ref:`String<class_String>` | :ref:`source_code<class_Script_property_source_code>` |
  28. +-----------------------------+-------------------------------------------------------+
  29. .. rst-class:: classref-reftable-group
  30. Methods
  31. -------
  32. .. table::
  33. :widths: auto
  34. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`bool<class_bool>` | :ref:`can_instance<class_Script_method_can_instance>` **(** **)** |const| |
  36. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Script<class_Script>` | :ref:`get_base_script<class_Script_method_get_base_script>` **(** **)** |const| |
  38. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`String<class_String>` | :ref:`get_instance_base_type<class_Script_method_get_instance_base_type>` **(** **)** |const| |
  40. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Variant<class_Variant>` | :ref:`get_property_default_value<class_Script_method_get_property_default_value>` **(** :ref:`String<class_String>` property **)** |
  42. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_script_constant_map<class_Script_method_get_script_constant_map>` **(** **)** |
  44. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Array<class_Array>` | :ref:`get_script_method_list<class_Script_method_get_script_method_list>` **(** **)** |
  46. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Array<class_Array>` | :ref:`get_script_property_list<class_Script_method_get_script_property_list>` **(** **)** |
  48. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Array<class_Array>` | :ref:`get_script_signal_list<class_Script_method_get_script_signal_list>` **(** **)** |
  50. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`has_script_signal<class_Script_method_has_script_signal>` **(** :ref:`String<class_String>` signal_name **)** |const| |
  52. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`has_source_code<class_Script_method_has_source_code>` **(** **)** |const| |
  54. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`instance_has<class_Script_method_instance_has>` **(** :ref:`Object<class_Object>` base_object **)** |const| |
  56. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`is_tool<class_Script_method_is_tool>` **(** **)** |const| |
  58. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`reload<class_Script_method_reload>` **(** :ref:`bool<class_bool>` keep_state=false **)** |
  60. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
  61. .. rst-class:: classref-section-separator
  62. ----
  63. .. rst-class:: classref-descriptions-group
  64. Property Descriptions
  65. ---------------------
  66. .. _class_Script_property_source_code:
  67. .. rst-class:: classref-property
  68. :ref:`String<class_String>` **source_code**
  69. .. rst-class:: classref-property-setget
  70. - void **set_source_code** **(** :ref:`String<class_String>` value **)**
  71. - :ref:`String<class_String>` **get_source_code** **(** **)**
  72. The script source code or an empty string if source code is not available. When set, does not reload the class implementation automatically.
  73. .. rst-class:: classref-section-separator
  74. ----
  75. .. rst-class:: classref-descriptions-group
  76. Method Descriptions
  77. -------------------
  78. .. _class_Script_method_can_instance:
  79. .. rst-class:: classref-method
  80. :ref:`bool<class_bool>` **can_instance** **(** **)** |const|
  81. Returns ``true`` if the script can be instanced.
  82. .. rst-class:: classref-item-separator
  83. ----
  84. .. _class_Script_method_get_base_script:
  85. .. rst-class:: classref-method
  86. :ref:`Script<class_Script>` **get_base_script** **(** **)** |const|
  87. Returns the script directly inherited by this script.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_Script_method_get_instance_base_type:
  91. .. rst-class:: classref-method
  92. :ref:`String<class_String>` **get_instance_base_type** **(** **)** |const|
  93. Returns the script's base type.
  94. .. rst-class:: classref-item-separator
  95. ----
  96. .. _class_Script_method_get_property_default_value:
  97. .. rst-class:: classref-method
  98. :ref:`Variant<class_Variant>` **get_property_default_value** **(** :ref:`String<class_String>` property **)**
  99. Returns the default value of the specified property.
  100. .. rst-class:: classref-item-separator
  101. ----
  102. .. _class_Script_method_get_script_constant_map:
  103. .. rst-class:: classref-method
  104. :ref:`Dictionary<class_Dictionary>` **get_script_constant_map** **(** **)**
  105. Returns a dictionary containing constant names and their values.
  106. .. rst-class:: classref-item-separator
  107. ----
  108. .. _class_Script_method_get_script_method_list:
  109. .. rst-class:: classref-method
  110. :ref:`Array<class_Array>` **get_script_method_list** **(** **)**
  111. Returns the list of methods in this **Script**.
  112. .. rst-class:: classref-item-separator
  113. ----
  114. .. _class_Script_method_get_script_property_list:
  115. .. rst-class:: classref-method
  116. :ref:`Array<class_Array>` **get_script_property_list** **(** **)**
  117. Returns the list of properties in this **Script**.
  118. .. rst-class:: classref-item-separator
  119. ----
  120. .. _class_Script_method_get_script_signal_list:
  121. .. rst-class:: classref-method
  122. :ref:`Array<class_Array>` **get_script_signal_list** **(** **)**
  123. Returns the list of user signals defined in this **Script**.
  124. .. rst-class:: classref-item-separator
  125. ----
  126. .. _class_Script_method_has_script_signal:
  127. .. rst-class:: classref-method
  128. :ref:`bool<class_bool>` **has_script_signal** **(** :ref:`String<class_String>` signal_name **)** |const|
  129. Returns ``true`` if the script, or a base class, defines a signal with the given name.
  130. .. rst-class:: classref-item-separator
  131. ----
  132. .. _class_Script_method_has_source_code:
  133. .. rst-class:: classref-method
  134. :ref:`bool<class_bool>` **has_source_code** **(** **)** |const|
  135. Returns ``true`` if the script contains non-empty source code.
  136. .. rst-class:: classref-item-separator
  137. ----
  138. .. _class_Script_method_instance_has:
  139. .. rst-class:: classref-method
  140. :ref:`bool<class_bool>` **instance_has** **(** :ref:`Object<class_Object>` base_object **)** |const|
  141. Returns ``true`` if ``base_object`` is an instance of this script.
  142. .. rst-class:: classref-item-separator
  143. ----
  144. .. _class_Script_method_is_tool:
  145. .. rst-class:: classref-method
  146. :ref:`bool<class_bool>` **is_tool** **(** **)** |const|
  147. Returns ``true`` if the script is a tool script. A tool script can run in the editor.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_Script_method_reload:
  151. .. rst-class:: classref-method
  152. :ref:`Error<enum_@GlobalScope_Error>` **reload** **(** :ref:`bool<class_bool>` keep_state=false **)**
  153. Reloads the script's class implementation. Returns an error code.
  154. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  155. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  156. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  157. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`