class_script.rst 11 KB

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