class_script.rst 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Script.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Script:
  6. Script
  7. ======
  8. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`CSharpScript<class_CSharpScript>`, :ref:`GDScript<class_GDScript>`, :ref:`VisualScript<class_VisualScript>`
  10. A class stored as a resource.
  11. Description
  12. -----------
  13. A class stored as a resource. A script extends the functionality of all objects that instance it.
  14. 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.
  15. 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.
  16. Tutorials
  17. ---------
  18. - :doc:`Scripting documentation index <../tutorials/scripting/index>`
  19. Properties
  20. ----------
  21. +-----------------------------+-------------------------------------------------------+
  22. | :ref:`String<class_String>` | :ref:`source_code<class_Script_property_source_code>` |
  23. +-----------------------------+-------------------------------------------------------+
  24. Methods
  25. -------
  26. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`bool<class_bool>` | :ref:`can_instantiate<class_Script_method_can_instantiate>` **(** **)** |const| |
  28. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Script<class_Script>` | :ref:`get_base_script<class_Script_method_get_base_script>` **(** **)** |const| |
  30. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`StringName<class_StringName>` | :ref:`get_instance_base_type<class_Script_method_get_instance_base_type>` **(** **)** |const| |
  32. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Variant<class_Variant>` | :ref:`get_property_default_value<class_Script_method_get_property_default_value>` **(** :ref:`StringName<class_StringName>` property **)** |
  34. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_script_constant_map<class_Script_method_get_script_constant_map>` **(** **)** |
  36. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Array<class_Array>` | :ref:`get_script_method_list<class_Script_method_get_script_method_list>` **(** **)** |
  38. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Array<class_Array>` | :ref:`get_script_property_list<class_Script_method_get_script_property_list>` **(** **)** |
  40. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Array<class_Array>` | :ref:`get_script_signal_list<class_Script_method_get_script_signal_list>` **(** **)** |
  42. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`has_script_signal<class_Script_method_has_script_signal>` **(** :ref:`StringName<class_StringName>` signal_name **)** |const| |
  44. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`has_source_code<class_Script_method_has_source_code>` **(** **)** |const| |
  46. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`instance_has<class_Script_method_instance_has>` **(** :ref:`Object<class_Object>` base_object **)** |const| |
  48. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`bool<class_bool>` | :ref:`is_tool<class_Script_method_is_tool>` **(** **)** |const| |
  50. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`reload<class_Script_method_reload>` **(** :ref:`bool<class_bool>` keep_state=false **)** |
  52. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  53. Property Descriptions
  54. ---------------------
  55. .. _class_Script_property_source_code:
  56. - :ref:`String<class_String>` **source_code**
  57. +----------+------------------------+
  58. | *Setter* | set_source_code(value) |
  59. +----------+------------------------+
  60. | *Getter* | get_source_code() |
  61. +----------+------------------------+
  62. The script source code or an empty string if source code is not available. When set, does not reload the class implementation automatically.
  63. Method Descriptions
  64. -------------------
  65. .. _class_Script_method_can_instantiate:
  66. - :ref:`bool<class_bool>` **can_instantiate** **(** **)** |const|
  67. Returns ``true`` if the script can be instantiated.
  68. ----
  69. .. _class_Script_method_get_base_script:
  70. - :ref:`Script<class_Script>` **get_base_script** **(** **)** |const|
  71. Returns the script directly inherited by this script.
  72. ----
  73. .. _class_Script_method_get_instance_base_type:
  74. - :ref:`StringName<class_StringName>` **get_instance_base_type** **(** **)** |const|
  75. Returns the script's base type.
  76. ----
  77. .. _class_Script_method_get_property_default_value:
  78. - :ref:`Variant<class_Variant>` **get_property_default_value** **(** :ref:`StringName<class_StringName>` property **)**
  79. Returns the default value of the specified property.
  80. ----
  81. .. _class_Script_method_get_script_constant_map:
  82. - :ref:`Dictionary<class_Dictionary>` **get_script_constant_map** **(** **)**
  83. Returns a dictionary containing constant names and their values.
  84. ----
  85. .. _class_Script_method_get_script_method_list:
  86. - :ref:`Array<class_Array>` **get_script_method_list** **(** **)**
  87. Returns the list of methods in this ``Script``.
  88. ----
  89. .. _class_Script_method_get_script_property_list:
  90. - :ref:`Array<class_Array>` **get_script_property_list** **(** **)**
  91. Returns the list of properties in this ``Script``.
  92. ----
  93. .. _class_Script_method_get_script_signal_list:
  94. - :ref:`Array<class_Array>` **get_script_signal_list** **(** **)**
  95. Returns the list of user signals defined in this ``Script``.
  96. ----
  97. .. _class_Script_method_has_script_signal:
  98. - :ref:`bool<class_bool>` **has_script_signal** **(** :ref:`StringName<class_StringName>` signal_name **)** |const|
  99. Returns ``true`` if the script, or a base class, defines a signal with the given name.
  100. ----
  101. .. _class_Script_method_has_source_code:
  102. - :ref:`bool<class_bool>` **has_source_code** **(** **)** |const|
  103. Returns ``true`` if the script contains non-empty source code.
  104. ----
  105. .. _class_Script_method_instance_has:
  106. - :ref:`bool<class_bool>` **instance_has** **(** :ref:`Object<class_Object>` base_object **)** |const|
  107. Returns ``true`` if ``base_object`` is an instance of this script.
  108. ----
  109. .. _class_Script_method_is_tool:
  110. - :ref:`bool<class_bool>` **is_tool** **(** **)** |const|
  111. Returns ``true`` if the script is a tool script. A tool script can run in the editor.
  112. ----
  113. .. _class_Script_method_reload:
  114. - :ref:`Error<enum_@GlobalScope_Error>` **reload** **(** :ref:`bool<class_bool>` keep_state=false **)**
  115. Reloads the script's class implementation. Returns an error code.
  116. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  117. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  118. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  119. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  120. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  121. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`