[email protected] 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  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.1/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.1/modules/gdscript/doc_classes/@GDScript.xml.
  6. .. _class_@GDScript:
  7. @GDScript
  8. =========
  9. Built-in GDScript constants, functions, and annotations.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. A list of GDScript-specific utility functions and annotations accessible from any script.
  14. For the list of the global functions and constants see :ref:`@GlobalScope<class_@GlobalScope>`.
  15. .. rst-class:: classref-introduction-group
  16. Tutorials
  17. ---------
  18. - :doc:`GDScript exports <../tutorials/scripting/gdscript/gdscript_exports>`
  19. .. rst-class:: classref-reftable-group
  20. Methods
  21. -------
  22. .. table::
  23. :widths: auto
  24. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Color<class_Color>` | :ref:`Color8<class_@GDScript_method_Color8>` **(** :ref:`int<class_int>` r8, :ref:`int<class_int>` g8, :ref:`int<class_int>` b8, :ref:`int<class_int>` a8=255 **)** |
  26. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`assert<class_@GDScript_method_assert>` **(** :ref:`bool<class_bool>` condition, :ref:`String<class_String>` message="" **)** |
  28. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`String<class_String>` | :ref:`char<class_@GDScript_method_char>` **(** :ref:`int<class_int>` char **)** |
  30. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Variant<class_Variant>` | :ref:`convert<class_@GDScript_method_convert>` **(** :ref:`Variant<class_Variant>` what, :ref:`int<class_int>` type **)** |
  32. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Object<class_Object>` | :ref:`dict_to_inst<class_@GDScript_method_dict_to_inst>` **(** :ref:`Dictionary<class_Dictionary>` dictionary **)** |
  34. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Array<class_Array>` | :ref:`get_stack<class_@GDScript_method_get_stack>` **(** **)** |
  36. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Dictionary<class_Dictionary>` | :ref:`inst_to_dict<class_@GDScript_method_inst_to_dict>` **(** :ref:`Object<class_Object>` instance **)** |
  38. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`is_instance_of<class_@GDScript_method_is_instance_of>` **(** :ref:`Variant<class_Variant>` value, :ref:`Variant<class_Variant>` type **)** |
  40. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`int<class_int>` | :ref:`len<class_@GDScript_method_len>` **(** :ref:`Variant<class_Variant>` var **)** |
  42. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Resource<class_Resource>` | :ref:`load<class_@GDScript_method_load>` **(** :ref:`String<class_String>` path **)** |
  44. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Resource<class_Resource>` | :ref:`preload<class_@GDScript_method_preload>` **(** :ref:`String<class_String>` path **)** |
  46. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`print_debug<class_@GDScript_method_print_debug>` **(** ... **)** |vararg| |
  48. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`print_stack<class_@GDScript_method_print_stack>` **(** **)** |
  50. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Array<class_Array>` | :ref:`range<class_@GDScript_method_range>` **(** ... **)** |vararg| |
  52. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`type_exists<class_@GDScript_method_type_exists>` **(** :ref:`StringName<class_StringName>` type **)** |
  54. +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. .. rst-class:: classref-section-separator
  56. ----
  57. .. rst-class:: classref-descriptions-group
  58. Constants
  59. ---------
  60. .. _class_@GDScript_constant_PI:
  61. .. rst-class:: classref-constant
  62. **PI** = ``3.14159265358979``
  63. Constant that represents how many times the diameter of a circle fits around its perimeter. This is equivalent to ``TAU / 2``, or 180 degrees in rotations.
  64. .. _class_@GDScript_constant_TAU:
  65. .. rst-class:: classref-constant
  66. **TAU** = ``6.28318530717959``
  67. The circle constant, the circumference of the unit circle in radians. This is equivalent to ``PI * 2``, or 360 degrees in rotations.
  68. .. _class_@GDScript_constant_INF:
  69. .. rst-class:: classref-constant
  70. **INF** = ``inf``
  71. Positive floating-point infinity. This is the result of floating-point division when the divisor is ``0.0``. For negative infinity, use ``-INF``. Dividing by ``-0.0`` will result in negative infinity if the numerator is positive, so dividing by ``0.0`` is not the same as dividing by ``-0.0`` (despite ``0.0 == -0.0`` returning ``true``).
  72. \ **Warning:** Numeric infinity is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer number by ``0`` will not result in :ref:`INF<class_@GDScript_constant_INF>` and will result in a run-time error instead.
  73. .. _class_@GDScript_constant_NAN:
  74. .. rst-class:: classref-constant
  75. **NAN** = ``nan``
  76. "Not a Number", an invalid floating-point value. :ref:`NAN<class_@GDScript_constant_NAN>` has special properties, including that ``!=`` always returns ``true``, while other comparison operators always return ``false``. This is true even when comparing with itself (``NAN == NAN`` returns ``false`` and ``NAN != NAN`` returns ``true``). It is returned by some invalid operations, such as dividing floating-point ``0.0`` by ``0.0``.
  77. \ **Warning:** "Not a Number" is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer ``0`` by ``0`` will not result in :ref:`NAN<class_@GDScript_constant_NAN>` and will result in a run-time error instead.
  78. .. rst-class:: classref-section-separator
  79. ----
  80. Annotations
  81. -----------
  82. .. _class_@GDScript_annotation_@export:
  83. .. rst-class:: classref-annotation
  84. **@export** **(** **)**
  85. Mark the following property as exported (editable in the Inspector dock and saved to disk). To control the type of the exported property, use the type hint notation.
  86. ::
  87. @export var string = ""
  88. @export var int_number = 5
  89. @export var float_number: float = 5
  90. @export var image: Image
  91. .. rst-class:: classref-item-separator
  92. ----
  93. .. _class_@GDScript_annotation_@export_category:
  94. .. rst-class:: classref-annotation
  95. **@export_category** **(** :ref:`String<class_String>` name **)**
  96. Define a new category for the following exported properties. This helps to organize properties in the Inspector dock.
  97. See also :ref:`@GlobalScope.PROPERTY_USAGE_CATEGORY<class_@GlobalScope_constant_PROPERTY_USAGE_CATEGORY>`.
  98. ::
  99. @export_category("Statistics")
  100. @export var hp = 30
  101. @export var speed = 1.25
  102. \ **Note:** Categories in the Inspector dock's list usually divide properties coming from different classes (Node, Node2D, Sprite, etc.). For better clarity, it's recommended to use :ref:`@export_group<class_@GDScript_annotation_@export_group>` and :ref:`@export_subgroup<class_@GDScript_annotation_@export_subgroup>`, instead.
  103. .. rst-class:: classref-item-separator
  104. ----
  105. .. _class_@GDScript_annotation_@export_color_no_alpha:
  106. .. rst-class:: classref-annotation
  107. **@export_color_no_alpha** **(** **)**
  108. Export a :ref:`Color<class_Color>` property without allowing its transparency (:ref:`Color.a<class_Color_property_a>`) to be edited.
  109. See also :ref:`@GlobalScope.PROPERTY_HINT_COLOR_NO_ALPHA<class_@GlobalScope_constant_PROPERTY_HINT_COLOR_NO_ALPHA>`.
  110. ::
  111. @export_color_no_alpha var dye_color: Color
  112. .. rst-class:: classref-item-separator
  113. ----
  114. .. _class_@GDScript_annotation_@export_dir:
  115. .. rst-class:: classref-annotation
  116. **@export_dir** **(** **)**
  117. Export a :ref:`String<class_String>` property as a path to a directory. The path will be limited to the project folder and its subfolders. See :ref:`@export_global_dir<class_@GDScript_annotation_@export_global_dir>` to allow picking from the entire filesystem.
  118. See also :ref:`@GlobalScope.PROPERTY_HINT_DIR<class_@GlobalScope_constant_PROPERTY_HINT_DIR>`.
  119. ::
  120. @export_dir var sprite_folder_path: String
  121. .. rst-class:: classref-item-separator
  122. ----
  123. .. _class_@GDScript_annotation_@export_enum:
  124. .. rst-class:: classref-annotation
  125. **@export_enum** **(** :ref:`String<class_String>` names, ... **)** |vararg|
  126. Export an :ref:`int<class_int>` or :ref:`String<class_String>` property as an enumerated list of options. If the property is an :ref:`int<class_int>`, then the index of the value is stored, in the same order the values are provided. You can add explicit values using a colon. If the property is a :ref:`String<class_String>`, then the value is stored.
  127. See also :ref:`@GlobalScope.PROPERTY_HINT_ENUM<class_@GlobalScope_constant_PROPERTY_HINT_ENUM>`.
  128. ::
  129. @export_enum("Warrior", "Magician", "Thief") var character_class: int
  130. @export_enum("Slow:30", "Average:60", "Very Fast:200") var character_speed: int
  131. @export_enum("Rebecca", "Mary", "Leah") var character_name: String
  132. If you want to set an initial value, you must specify it explicitly:
  133. ::
  134. @export_enum("Rebecca", "Mary", "Leah") var character_name: String = "Rebecca"
  135. If you want to use named GDScript enums, then use :ref:`@export<class_@GDScript_annotation_@export>` instead:
  136. ::
  137. enum CharacterName {REBECCA, MARY, LEAH}
  138. @export var character_name: CharacterName
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _class_@GDScript_annotation_@export_exp_easing:
  142. .. rst-class:: classref-annotation
  143. **@export_exp_easing** **(** :ref:`String<class_String>` hints="", ... **)** |vararg|
  144. Export a floating-point property with an easing editor widget. Additional hints can be provided to adjust the behavior of the widget. ``"attenuation"`` flips the curve, which makes it more intuitive for editing attenuation properties. ``"positive_only"`` limits values to only be greater than or equal to zero.
  145. See also :ref:`@GlobalScope.PROPERTY_HINT_EXP_EASING<class_@GlobalScope_constant_PROPERTY_HINT_EXP_EASING>`.
  146. ::
  147. @export_exp_easing var transition_speed
  148. @export_exp_easing("attenuation") var fading_attenuation
  149. @export_exp_easing("positive_only") var effect_power
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_@GDScript_annotation_@export_file:
  153. .. rst-class:: classref-annotation
  154. **@export_file** **(** :ref:`String<class_String>` filter="", ... **)** |vararg|
  155. Export a :ref:`String<class_String>` property as a path to a file. The path will be limited to the project folder and its subfolders. See :ref:`@export_global_file<class_@GDScript_annotation_@export_global_file>` to allow picking from the entire filesystem.
  156. If ``filter`` is provided, only matching files will be available for picking.
  157. See also :ref:`@GlobalScope.PROPERTY_HINT_FILE<class_@GlobalScope_constant_PROPERTY_HINT_FILE>`.
  158. ::
  159. @export_file var sound_effect_path: String
  160. @export_file("*.txt") var notes_path: String
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_@GDScript_annotation_@export_flags:
  164. .. rst-class:: classref-annotation
  165. **@export_flags** **(** :ref:`String<class_String>` names, ... **)** |vararg|
  166. Export an integer property as a bit flag field. This allows to store several "checked" or ``true`` values with one property, and comfortably select them from the Inspector dock.
  167. See also :ref:`@GlobalScope.PROPERTY_HINT_FLAGS<class_@GlobalScope_constant_PROPERTY_HINT_FLAGS>`.
  168. ::
  169. @export_flags("Fire", "Water", "Earth", "Wind") var spell_elements = 0
  170. You can add explicit values using a colon:
  171. ::
  172. @export_flags("Self:4", "Allies:8", "Foes:16") var spell_targets = 0
  173. You can also combine several flags:
  174. ::
  175. @export_flags("Self:4", "Allies:8", "Self and Allies:12", "Foes:16")
  176. var spell_targets = 0
  177. \ **Note:** A flag value must be at least ``1`` and at most ``2 ** 32 - 1``.
  178. \ **Note:** Unlike :ref:`@export_enum<class_@GDScript_annotation_@export_enum>`, the previous explicit value is not taken into account. In the following example, A is 16, B is 2, C is 4.
  179. ::
  180. @export_flags("A:16", "B", "C") var x
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _class_@GDScript_annotation_@export_flags_2d_navigation:
  184. .. rst-class:: classref-annotation
  185. **@export_flags_2d_navigation** **(** **)**
  186. Export an integer property as a bit flag field for 2D navigation layers. The widget in the Inspector dock will use the layer names defined in :ref:`ProjectSettings.layer_names/2d_navigation/layer_1<class_ProjectSettings_property_layer_names/2d_navigation/layer_1>`.
  187. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_2D_NAVIGATION<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_2D_NAVIGATION>`.
  188. ::
  189. @export_flags_2d_navigation var navigation_layers: int
  190. .. rst-class:: classref-item-separator
  191. ----
  192. .. _class_@GDScript_annotation_@export_flags_2d_physics:
  193. .. rst-class:: classref-annotation
  194. **@export_flags_2d_physics** **(** **)**
  195. Export an integer property as a bit flag field for 2D physics layers. The widget in the Inspector dock will use the layer names defined in :ref:`ProjectSettings.layer_names/2d_physics/layer_1<class_ProjectSettings_property_layer_names/2d_physics/layer_1>`.
  196. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_2D_PHYSICS<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_2D_PHYSICS>`.
  197. ::
  198. @export_flags_2d_physics var physics_layers: int
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_@GDScript_annotation_@export_flags_2d_render:
  202. .. rst-class:: classref-annotation
  203. **@export_flags_2d_render** **(** **)**
  204. Export an integer property as a bit flag field for 2D render layers. The widget in the Inspector dock will use the layer names defined in :ref:`ProjectSettings.layer_names/2d_render/layer_1<class_ProjectSettings_property_layer_names/2d_render/layer_1>`.
  205. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_2D_RENDER<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_2D_RENDER>`.
  206. ::
  207. @export_flags_2d_render var render_layers: int
  208. .. rst-class:: classref-item-separator
  209. ----
  210. .. _class_@GDScript_annotation_@export_flags_3d_navigation:
  211. .. rst-class:: classref-annotation
  212. **@export_flags_3d_navigation** **(** **)**
  213. Export an integer property as a bit flag field for 3D navigation layers. The widget in the Inspector dock will use the layer names defined in :ref:`ProjectSettings.layer_names/3d_navigation/layer_1<class_ProjectSettings_property_layer_names/3d_navigation/layer_1>`.
  214. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_3D_NAVIGATION<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_3D_NAVIGATION>`.
  215. ::
  216. @export_flags_3d_navigation var navigation_layers: int
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_@GDScript_annotation_@export_flags_3d_physics:
  220. .. rst-class:: classref-annotation
  221. **@export_flags_3d_physics** **(** **)**
  222. Export an integer property as a bit flag field for 3D physics layers. The widget in the Inspector dock will use the layer names defined in :ref:`ProjectSettings.layer_names/3d_physics/layer_1<class_ProjectSettings_property_layer_names/3d_physics/layer_1>`.
  223. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_3D_PHYSICS<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_3D_PHYSICS>`.
  224. ::
  225. @export_flags_3d_physics var physics_layers: int
  226. .. rst-class:: classref-item-separator
  227. ----
  228. .. _class_@GDScript_annotation_@export_flags_3d_render:
  229. .. rst-class:: classref-annotation
  230. **@export_flags_3d_render** **(** **)**
  231. Export an integer property as a bit flag field for 3D render layers. The widget in the Inspector dock will use the layer names defined in :ref:`ProjectSettings.layer_names/3d_render/layer_1<class_ProjectSettings_property_layer_names/3d_render/layer_1>`.
  232. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_3D_RENDER<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_3D_RENDER>`.
  233. ::
  234. @export_flags_3d_render var render_layers: int
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_@GDScript_annotation_@export_flags_avoidance:
  238. .. rst-class:: classref-annotation
  239. **@export_flags_avoidance** **(** **)**
  240. Export an integer property as a bit flag field for navigation avoidance layers. The widget in the Inspector dock will use the layer names defined in :ref:`ProjectSettings.layer_names/avoidance/layer_1<class_ProjectSettings_property_layer_names/avoidance/layer_1>`.
  241. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_AVOIDANCE<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_AVOIDANCE>`.
  242. ::
  243. @export_flags_avoidance var avoidance_layers: int
  244. .. rst-class:: classref-item-separator
  245. ----
  246. .. _class_@GDScript_annotation_@export_global_dir:
  247. .. rst-class:: classref-annotation
  248. **@export_global_dir** **(** **)**
  249. Export a :ref:`String<class_String>` property as an absolute path to a directory. The path can be picked from the entire filesystem. See :ref:`@export_dir<class_@GDScript_annotation_@export_dir>` to limit it to the project folder and its subfolders.
  250. See also :ref:`@GlobalScope.PROPERTY_HINT_GLOBAL_DIR<class_@GlobalScope_constant_PROPERTY_HINT_GLOBAL_DIR>`.
  251. ::
  252. @export_global_dir var sprite_folder_path: String
  253. .. rst-class:: classref-item-separator
  254. ----
  255. .. _class_@GDScript_annotation_@export_global_file:
  256. .. rst-class:: classref-annotation
  257. **@export_global_file** **(** :ref:`String<class_String>` filter="", ... **)** |vararg|
  258. Export a :ref:`String<class_String>` property as an absolute path to a file. The path can be picked from the entire filesystem. See :ref:`@export_file<class_@GDScript_annotation_@export_file>` to limit it to the project folder and its subfolders.
  259. If ``filter`` is provided, only matching files will be available for picking.
  260. See also :ref:`@GlobalScope.PROPERTY_HINT_GLOBAL_FILE<class_@GlobalScope_constant_PROPERTY_HINT_GLOBAL_FILE>`.
  261. ::
  262. @export_global_file var sound_effect_path: String
  263. @export_global_file("*.txt") var notes_path: String
  264. .. rst-class:: classref-item-separator
  265. ----
  266. .. _class_@GDScript_annotation_@export_group:
  267. .. rst-class:: classref-annotation
  268. **@export_group** **(** :ref:`String<class_String>` name, :ref:`String<class_String>` prefix="" **)**
  269. Define a new group for the following exported properties. This helps to organize properties in the Inspector dock. Groups can be added with an optional ``prefix``, which would make group to only consider properties that have this prefix. The grouping will break on the first property that doesn't have a prefix. The prefix is also removed from the property's name in the Inspector dock.
  270. If no ``prefix`` is provided, then every following property will be added to the group. The group ends when then next group or category is defined. You can also force end a group by using this annotation with empty strings for parameters, ``@export_group("", "")``.
  271. Groups cannot be nested, use :ref:`@export_subgroup<class_@GDScript_annotation_@export_subgroup>` to add subgroups within groups.
  272. See also :ref:`@GlobalScope.PROPERTY_USAGE_GROUP<class_@GlobalScope_constant_PROPERTY_USAGE_GROUP>`.
  273. ::
  274. @export_group("Racer Properties")
  275. @export var nickname = "Nick"
  276. @export var age = 26
  277. @export_group("Car Properties", "car_")
  278. @export var car_label = "Speedy"
  279. @export var car_number = 3
  280. @export_group("", "")
  281. @export var ungrouped_number = 3
  282. .. rst-class:: classref-item-separator
  283. ----
  284. .. _class_@GDScript_annotation_@export_multiline:
  285. .. rst-class:: classref-annotation
  286. **@export_multiline** **(** **)**
  287. Export a :ref:`String<class_String>` property with a large :ref:`TextEdit<class_TextEdit>` widget instead of a :ref:`LineEdit<class_LineEdit>`. This adds support for multiline content and makes it easier to edit large amount of text stored in the property.
  288. See also :ref:`@GlobalScope.PROPERTY_HINT_MULTILINE_TEXT<class_@GlobalScope_constant_PROPERTY_HINT_MULTILINE_TEXT>`.
  289. ::
  290. @export_multiline var character_biography
  291. .. rst-class:: classref-item-separator
  292. ----
  293. .. _class_@GDScript_annotation_@export_node_path:
  294. .. rst-class:: classref-annotation
  295. **@export_node_path** **(** :ref:`String<class_String>` type="", ... **)** |vararg|
  296. Export a :ref:`NodePath<class_NodePath>` property with a filter for allowed node types.
  297. See also :ref:`@GlobalScope.PROPERTY_HINT_NODE_PATH_VALID_TYPES<class_@GlobalScope_constant_PROPERTY_HINT_NODE_PATH_VALID_TYPES>`.
  298. ::
  299. @export_node_path("Button", "TouchScreenButton") var some_button
  300. .. rst-class:: classref-item-separator
  301. ----
  302. .. _class_@GDScript_annotation_@export_placeholder:
  303. .. rst-class:: classref-annotation
  304. **@export_placeholder** **(** :ref:`String<class_String>` placeholder **)**
  305. Export a :ref:`String<class_String>` property with a placeholder text displayed in the editor widget when no value is present.
  306. See also :ref:`@GlobalScope.PROPERTY_HINT_PLACEHOLDER_TEXT<class_@GlobalScope_constant_PROPERTY_HINT_PLACEHOLDER_TEXT>`.
  307. ::
  308. @export_placeholder("Name in lowercase") var character_id: String
  309. .. rst-class:: classref-item-separator
  310. ----
  311. .. _class_@GDScript_annotation_@export_range:
  312. .. rst-class:: classref-annotation
  313. **@export_range** **(** :ref:`float<class_float>` min, :ref:`float<class_float>` max, :ref:`float<class_float>` step=1.0, :ref:`String<class_String>` extra_hints="", ... **)** |vararg|
  314. Export an :ref:`int<class_int>` or :ref:`float<class_float>` property as a range value. The range must be defined by ``min`` and ``max``, as well as an optional ``step`` and a variety of extra hints. The ``step`` defaults to ``1`` for integer properties. For floating-point numbers this value depends on your ``EditorSettings.interface/inspector/default_float_step`` setting.
  315. If hints ``"or_greater"`` and ``"or_less"`` are provided, the editor widget will not cap the value at range boundaries. The ``"exp"`` hint will make the edited values on range to change exponentially. The ``"hide_slider"`` hint will hide the slider element of the editor widget.
  316. Hints also allow to indicate the units for the edited value. Using ``"radians"`` you can specify that the actual value is in radians, but should be displayed in degrees in the Inspector dock. ``"degrees"`` allows to add a degree sign as a unit suffix. Finally, a custom suffix can be provided using ``"suffix:unit"``, where "unit" can be any string.
  317. See also :ref:`@GlobalScope.PROPERTY_HINT_RANGE<class_@GlobalScope_constant_PROPERTY_HINT_RANGE>`.
  318. ::
  319. @export_range(0, 20) var number
  320. @export_range(-10, 20) var number
  321. @export_range(-10, 20, 0.2) var number: float
  322. @export_range(0, 100, 1, "or_greater") var power_percent
  323. @export_range(0, 100, 1, "or_greater", "or_less") var health_delta
  324. @export_range(-3.14, 3.14, 0.001, "radians") var angle_radians
  325. @export_range(0, 360, 1, "degrees") var angle_degrees
  326. @export_range(-8, 8, 2, "suffix:px") var target_offset
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_@GDScript_annotation_@export_subgroup:
  330. .. rst-class:: classref-annotation
  331. **@export_subgroup** **(** :ref:`String<class_String>` name, :ref:`String<class_String>` prefix="" **)**
  332. Define a new subgroup for the following exported properties. This helps to organize properties in the Inspector dock. Subgroups work exactly like groups, except they need a parent group to exist. See :ref:`@export_group<class_@GDScript_annotation_@export_group>`.
  333. See also :ref:`@GlobalScope.PROPERTY_USAGE_SUBGROUP<class_@GlobalScope_constant_PROPERTY_USAGE_SUBGROUP>`.
  334. ::
  335. @export_group("Racer Properties")
  336. @export var nickname = "Nick"
  337. @export var age = 26
  338. @export_subgroup("Car Properties", "car_")
  339. @export var car_label = "Speedy"
  340. @export var car_number = 3
  341. \ **Note:** Subgroups cannot be nested, they only provide one extra level of depth. Just like the next group ends the previous group, so do the subsequent subgroups.
  342. .. rst-class:: classref-item-separator
  343. ----
  344. .. _class_@GDScript_annotation_@icon:
  345. .. rst-class:: classref-annotation
  346. **@icon** **(** :ref:`String<class_String>` icon_path **)**
  347. Add a custom icon to the current script. The script must be registered as a global class using the ``class_name`` keyword for this to have a visible effect. The icon specified at ``icon_path`` is displayed in the Scene dock for every node of that class, as well as in various editor dialogs.
  348. ::
  349. @icon("res://path/to/class/icon.svg")
  350. \ **Note:** Only the script can have a custom icon. Inner classes are not supported.
  351. \ **Note:** As annotations describe their subject, the ``@icon`` annotation must be placed before the class definition and inheritance.
  352. \ **Note:** Unlike other annotations, the argument of the ``@icon`` annotation must be a string literal (constant expressions are not supported).
  353. .. rst-class:: classref-item-separator
  354. ----
  355. .. _class_@GDScript_annotation_@onready:
  356. .. rst-class:: classref-annotation
  357. **@onready** **(** **)**
  358. Mark the following property as assigned when the :ref:`Node<class_Node>` is ready. Values for these properties are not assigned immediately when the node is initialized (:ref:`Object._init<class_Object_method__init>`), and instead are computed and stored right before :ref:`Node._ready<class_Node_method__ready>`.
  359. ::
  360. @onready var character_name: Label = $Label
  361. .. rst-class:: classref-item-separator
  362. ----
  363. .. _class_@GDScript_annotation_@rpc:
  364. .. rst-class:: classref-annotation
  365. **@rpc** **(** :ref:`String<class_String>` mode="authority", :ref:`String<class_String>` sync="call_remote", :ref:`String<class_String>` transfer_mode="unreliable", :ref:`int<class_int>` transfer_channel=0 **)**
  366. Mark the following method for remote procedure calls. See :doc:`High-level multiplayer <../tutorials/networking/high_level_multiplayer>`.
  367. If ``mode`` is set as ``"any_peer"``, allows any peer to call this RPC function. Otherwise, only the authority peer is allowed to call it and ``mode`` should be kept as ``"authority"``. When configuring functions as RPCs with :ref:`Node.rpc_config<class_Node_method_rpc_config>`, each of these modes respectively corresponds to the :ref:`MultiplayerAPI.RPC_MODE_AUTHORITY<class_MultiplayerAPI_constant_RPC_MODE_AUTHORITY>` and :ref:`MultiplayerAPI.RPC_MODE_ANY_PEER<class_MultiplayerAPI_constant_RPC_MODE_ANY_PEER>` RPC modes. See :ref:`RPCMode<enum_MultiplayerAPI_RPCMode>`. If a peer that is not the authority tries to call a function that is only allowed for the authority, the function will not be executed. If the error can be detected locally (when the RPC configuration is consistent between the local and the remote peer), an error message will be displayed on the sender peer. Otherwise, the remote peer will detect the error and print an error there.
  368. If ``sync`` is set as ``"call_remote"``, the function will only be executed on the remote peer, but not locally. To run this function locally too, set ``sync`` to ``"call_local"``. When configuring functions as RPCs with :ref:`Node.rpc_config<class_Node_method_rpc_config>`, this is equivalent to setting `call_local` to `true`.
  369. The ``transfer_mode`` accepted values are ``"unreliable"``, ``"unreliable_ordered"``, or ``"reliable"``. It sets the transfer mode of the underlying :ref:`MultiplayerPeer<class_MultiplayerPeer>`. See :ref:`MultiplayerPeer.transfer_mode<class_MultiplayerPeer_property_transfer_mode>`.
  370. The ``transfer_channel`` defines the channel of the underlying :ref:`MultiplayerPeer<class_MultiplayerPeer>`. See :ref:`MultiplayerPeer.transfer_channel<class_MultiplayerPeer_property_transfer_channel>`.
  371. The order of ``mode``, ``sync`` and ``transfer_mode`` does not matter, but values related to the same argument must not be used more than once. ``transfer_channel`` always has to be the 4th argument (you must specify 3 preceding arguments).
  372. ::
  373. @rpc
  374. func fn(): pass
  375. @rpc("any_peer", "unreliable_ordered")
  376. func fn_update_pos(): pass
  377. @rpc("authority", "call_remote", "unreliable", 0) # Equivalent to @rpc
  378. func fn_default(): pass
  379. .. rst-class:: classref-item-separator
  380. ----
  381. .. _class_@GDScript_annotation_@static_unload:
  382. .. rst-class:: classref-annotation
  383. **@static_unload** **(** **)**
  384. Make a script with static variables to not persist after all references are lost. If the script is loaded again the static variables will revert to their default values.
  385. \ **Note:** As annotations describe their subject, the :ref:`@static_unload<class_@GDScript_annotation_@static_unload>` annotation must be placed before the class definition and inheritance.
  386. \ **Warning:** Currently, due to a bug, scripts are never freed, even if :ref:`@static_unload<class_@GDScript_annotation_@static_unload>` annotation is used.
  387. .. rst-class:: classref-item-separator
  388. ----
  389. .. _class_@GDScript_annotation_@tool:
  390. .. rst-class:: classref-annotation
  391. **@tool** **(** **)**
  392. Mark the current script as a tool script, allowing it to be loaded and executed by the editor. See :doc:`Running code in the editor <../tutorials/plugins/running_code_in_the_editor>`.
  393. ::
  394. @tool
  395. extends Node
  396. \ **Note:** As annotations describe their subject, the ``@tool`` annotation must be placed before the class definition and inheritance.
  397. .. rst-class:: classref-item-separator
  398. ----
  399. .. _class_@GDScript_annotation_@warning_ignore:
  400. .. rst-class:: classref-annotation
  401. **@warning_ignore** **(** :ref:`String<class_String>` warning, ... **)** |vararg|
  402. Mark the following statement to ignore the specified ``warning``. See :doc:`GDScript warning system <../tutorials/scripting/gdscript/warning_system>`.
  403. ::
  404. func test():
  405. print("hello")
  406. return
  407. @warning_ignore("unreachable_code")
  408. print("unreachable")
  409. .. rst-class:: classref-section-separator
  410. ----
  411. .. rst-class:: classref-descriptions-group
  412. Method Descriptions
  413. -------------------
  414. .. _class_@GDScript_method_Color8:
  415. .. rst-class:: classref-method
  416. :ref:`Color<class_Color>` **Color8** **(** :ref:`int<class_int>` r8, :ref:`int<class_int>` g8, :ref:`int<class_int>` b8, :ref:`int<class_int>` a8=255 **)**
  417. Returns a :ref:`Color<class_Color>` constructed from red (``r8``), green (``g8``), blue (``b8``), and optionally alpha (``a8``) integer channels, each divided by ``255.0`` for their final value. Using :ref:`Color8<class_@GDScript_method_Color8>` instead of the standard :ref:`Color<class_Color>` constructor is useful when you need to match exact color values in an :ref:`Image<class_Image>`.
  418. ::
  419. var red = Color8(255, 0, 0) # Same as Color(1, 0, 0).
  420. var dark_blue = Color8(0, 0, 51) # Same as Color(0, 0, 0.2).
  421. var my_color = Color8(306, 255, 0, 102) # Same as Color(1.2, 1, 0, 0.4).
  422. \ **Note:** Due to the lower precision of :ref:`Color8<class_@GDScript_method_Color8>` compared to the standard :ref:`Color<class_Color>` constructor, a color created with :ref:`Color8<class_@GDScript_method_Color8>` will generally not be equal to the same color created with the standard :ref:`Color<class_Color>` constructor. Use :ref:`Color.is_equal_approx<class_Color_method_is_equal_approx>` for comparisons to avoid issues with floating-point precision error.
  423. .. rst-class:: classref-item-separator
  424. ----
  425. .. _class_@GDScript_method_assert:
  426. .. rst-class:: classref-method
  427. void **assert** **(** :ref:`bool<class_bool>` condition, :ref:`String<class_String>` message="" **)**
  428. Asserts that the ``condition`` is ``true``. If the ``condition`` is ``false``, an error is generated. When running from the editor, the running project will also be paused until you resume it. This can be used as a stronger form of :ref:`@GlobalScope.push_error<class_@GlobalScope_method_push_error>` for reporting errors to project developers or add-on users.
  429. An optional ``message`` can be shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed.
  430. \ **Warning:** For performance reasons, the code inside :ref:`assert<class_@GDScript_method_assert>` is only executed in debug builds or when running the project from the editor. Don't include code that has side effects in an :ref:`assert<class_@GDScript_method_assert>` call. Otherwise, the project will behave differently when exported in release mode.
  431. ::
  432. # Imagine we always want speed to be between 0 and 20.
  433. var speed = -10
  434. assert(speed < 20) # True, the program will continue.
  435. assert(speed >= 0) # False, the program will stop.
  436. assert(speed >= 0 and speed < 20) # You can also combine the two conditional statements in one check.
  437. assert(speed < 20, "the speed limit is 20") # Show a message.
  438. \ **Note:** :ref:`assert<class_@GDScript_method_assert>` is a keyword, not a function. So you cannot access it as a :ref:`Callable<class_Callable>` or use it inside expressions.
  439. .. rst-class:: classref-item-separator
  440. ----
  441. .. _class_@GDScript_method_char:
  442. .. rst-class:: classref-method
  443. :ref:`String<class_String>` **char** **(** :ref:`int<class_int>` char **)**
  444. Returns a single character (as a :ref:`String<class_String>`) of the given Unicode code point (which is compatible with ASCII code).
  445. ::
  446. a = char(65) # a is "A"
  447. a = char(65 + 32) # a is "a"
  448. a = char(8364) # a is "€"
  449. .. rst-class:: classref-item-separator
  450. ----
  451. .. _class_@GDScript_method_convert:
  452. .. rst-class:: classref-method
  453. :ref:`Variant<class_Variant>` **convert** **(** :ref:`Variant<class_Variant>` what, :ref:`int<class_int>` type **)**
  454. Converts ``what`` to ``type`` in the best way possible. The ``type`` uses the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` values.
  455. ::
  456. var a = [4, 2.5, 1.2]
  457. print(a is Array) # Prints true
  458. var b = convert(a, TYPE_PACKED_BYTE_ARRAY)
  459. print(b) # Prints [4, 2, 1]
  460. print(b is Array) # Prints false
  461. .. rst-class:: classref-item-separator
  462. ----
  463. .. _class_@GDScript_method_dict_to_inst:
  464. .. rst-class:: classref-method
  465. :ref:`Object<class_Object>` **dict_to_inst** **(** :ref:`Dictionary<class_Dictionary>` dictionary **)**
  466. Converts a ``dictionary`` (created with :ref:`inst_to_dict<class_@GDScript_method_inst_to_dict>`) back to an Object instance. Can be useful for deserializing.
  467. .. rst-class:: classref-item-separator
  468. ----
  469. .. _class_@GDScript_method_get_stack:
  470. .. rst-class:: classref-method
  471. :ref:`Array<class_Array>` **get_stack** **(** **)**
  472. Returns an array of dictionaries representing the current call stack. See also :ref:`print_stack<class_@GDScript_method_print_stack>`.
  473. ::
  474. func _ready():
  475. foo()
  476. func foo():
  477. bar()
  478. func bar():
  479. print(get_stack())
  480. Starting from ``_ready()``, ``bar()`` would print:
  481. ::
  482. [{function:bar, line:12, source:res://script.gd}, {function:foo, line:9, source:res://script.gd}, {function:_ready, line:6, source:res://script.gd}]
  483. \ **Note:** This function only works if the running instance is connected to a debugging server (i.e. an editor instance). :ref:`get_stack<class_@GDScript_method_get_stack>` will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
  484. \ **Note:** Calling this function from a :ref:`Thread<class_Thread>` is not supported. Doing so will return an empty array.
  485. .. rst-class:: classref-item-separator
  486. ----
  487. .. _class_@GDScript_method_inst_to_dict:
  488. .. rst-class:: classref-method
  489. :ref:`Dictionary<class_Dictionary>` **inst_to_dict** **(** :ref:`Object<class_Object>` instance **)**
  490. Returns the passed ``instance`` converted to a Dictionary. Can be useful for serializing.
  491. \ **Note:** Cannot be used to serialize objects with built-in scripts attached or objects allocated within built-in scripts.
  492. ::
  493. var foo = "bar"
  494. func _ready():
  495. var d = inst_to_dict(self)
  496. print(d.keys())
  497. print(d.values())
  498. Prints out:
  499. ::
  500. [@subpath, @path, foo]
  501. [, res://test.gd, bar]
  502. .. rst-class:: classref-item-separator
  503. ----
  504. .. _class_@GDScript_method_is_instance_of:
  505. .. rst-class:: classref-method
  506. :ref:`bool<class_bool>` **is_instance_of** **(** :ref:`Variant<class_Variant>` value, :ref:`Variant<class_Variant>` type **)**
  507. Returns ``true`` if ``value`` is an instance of ``type``. The ``type`` value must be one of the following:
  508. - A constant from the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` enumeration, for example :ref:`@GlobalScope.TYPE_INT<class_@GlobalScope_constant_TYPE_INT>`.
  509. - An :ref:`Object<class_Object>`-derived class which exists in :ref:`ClassDB<class_ClassDB>`, for example :ref:`Node<class_Node>`.
  510. - A :ref:`Script<class_Script>` (you can use any class, including inner one).
  511. Unlike the right operand of the ``is`` operator, ``type`` can be a non-constant value. The ``is`` operator supports more features (such as typed arrays). Use the operator instead of this method if you do not need dynamic type checking.
  512. Examples:
  513. ::
  514. print(is_instance_of(a, TYPE_INT))
  515. print(is_instance_of(a, Node))
  516. print(is_instance_of(a, MyClass))
  517. print(is_instance_of(a, MyClass.InnerClass))
  518. \ **Note:** If ``value`` and/or ``type`` are freed objects (see :ref:`@GlobalScope.is_instance_valid<class_@GlobalScope_method_is_instance_valid>`), or ``type`` is not one of the above options, this method will raise a runtime error.
  519. See also :ref:`@GlobalScope.typeof<class_@GlobalScope_method_typeof>`, :ref:`type_exists<class_@GDScript_method_type_exists>`, :ref:`Array.is_same_typed<class_Array_method_is_same_typed>` (and other :ref:`Array<class_Array>` methods).
  520. .. rst-class:: classref-item-separator
  521. ----
  522. .. _class_@GDScript_method_len:
  523. .. rst-class:: classref-method
  524. :ref:`int<class_int>` **len** **(** :ref:`Variant<class_Variant>` var **)**
  525. Returns the length of the given Variant ``var``. The length can be the character count of a :ref:`String<class_String>`, the element count of any array type or the size of a :ref:`Dictionary<class_Dictionary>`. For every other Variant type, a run-time error is generated and execution is stopped.
  526. ::
  527. a = [1, 2, 3, 4]
  528. len(a) # Returns 4
  529. b = "Hello!"
  530. len(b) # Returns 6
  531. .. rst-class:: classref-item-separator
  532. ----
  533. .. _class_@GDScript_method_load:
  534. .. rst-class:: classref-method
  535. :ref:`Resource<class_Resource>` **load** **(** :ref:`String<class_String>` path **)**
  536. Returns a :ref:`Resource<class_Resource>` from the filesystem located at the absolute ``path``. Unless it's already referenced elsewhere (such as in another script or in the scene), the resource is loaded from disk on function call, which might cause a slight delay, especially when loading large scenes. To avoid unnecessary delays when loading something multiple times, either store the resource in a variable or use :ref:`preload<class_@GDScript_method_preload>`.
  537. \ **Note:** Resource paths can be obtained by right-clicking on a resource in the FileSystem dock and choosing "Copy Path", or by dragging the file from the FileSystem dock into the current script.
  538. ::
  539. # Load a scene called "main" located in the root of the project directory and cache it in a variable.
  540. var main = load("res://main.tscn") # main will contain a PackedScene resource.
  541. \ **Important:** Relative paths are *not* relative to the script calling this method, instead it is prefixed with ``"res://"``. Loading from relative paths might not work as expected.
  542. This function is a simplified version of :ref:`ResourceLoader.load<class_ResourceLoader_method_load>`, which can be used for more advanced scenarios.
  543. \ **Note:** Files have to be imported into the engine first to load them using this function. If you want to load :ref:`Image<class_Image>`\ s at run-time, you may use :ref:`Image.load<class_Image_method_load>`. If you want to import audio files, you can use the snippet described in :ref:`AudioStreamMP3.data<class_AudioStreamMP3_property_data>`.
  544. \ **Note:** If :ref:`ProjectSettings.editor/export/convert_text_resources_to_binary<class_ProjectSettings_property_editor/export/convert_text_resources_to_binary>` is ``true``, :ref:`load<class_@GDScript_method_load>` will not be able to read converted files in an exported project. If you rely on run-time loading of files present within the PCK, set :ref:`ProjectSettings.editor/export/convert_text_resources_to_binary<class_ProjectSettings_property_editor/export/convert_text_resources_to_binary>` to ``false``.
  545. .. rst-class:: classref-item-separator
  546. ----
  547. .. _class_@GDScript_method_preload:
  548. .. rst-class:: classref-method
  549. :ref:`Resource<class_Resource>` **preload** **(** :ref:`String<class_String>` path **)**
  550. Returns a :ref:`Resource<class_Resource>` from the filesystem located at ``path``. During run-time, the resource is loaded when the script is being parsed. This function effectively acts as a reference to that resource. Note that this function requires ``path`` to be a constant :ref:`String<class_String>`. If you want to load a resource from a dynamic/variable path, use :ref:`load<class_@GDScript_method_load>`.
  551. \ **Note:** Resource paths can be obtained by right-clicking on a resource in the Assets Panel and choosing "Copy Path", or by dragging the file from the FileSystem dock into the current script.
  552. ::
  553. # Create instance of a scene.
  554. var diamond = preload("res://diamond.tscn").instantiate()
  555. \ **Note:** :ref:`preload<class_@GDScript_method_preload>` is a keyword, not a function. So you cannot access it as a :ref:`Callable<class_Callable>`.
  556. .. rst-class:: classref-item-separator
  557. ----
  558. .. _class_@GDScript_method_print_debug:
  559. .. rst-class:: classref-method
  560. void **print_debug** **(** ... **)** |vararg|
  561. Like :ref:`@GlobalScope.print<class_@GlobalScope_method_print>`, but includes the current stack frame when running with the debugger turned on.
  562. The output in the console may look like the following:
  563. ::
  564. Test print
  565. At: res://test.gd:15:_process()
  566. \ **Note:** Calling this function from a :ref:`Thread<class_Thread>` is not supported. Doing so will instead print the thread ID.
  567. .. rst-class:: classref-item-separator
  568. ----
  569. .. _class_@GDScript_method_print_stack:
  570. .. rst-class:: classref-method
  571. void **print_stack** **(** **)**
  572. Prints a stack trace at the current code location. See also :ref:`get_stack<class_@GDScript_method_get_stack>`.
  573. The output in the console may look like the following:
  574. ::
  575. Frame 0 - res://test.gd:16 in function '_process'
  576. \ **Note:** This function only works if the running instance is connected to a debugging server (i.e. an editor instance). :ref:`print_stack<class_@GDScript_method_print_stack>` will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
  577. \ **Note:** Calling this function from a :ref:`Thread<class_Thread>` is not supported. Doing so will instead print the thread ID.
  578. .. rst-class:: classref-item-separator
  579. ----
  580. .. _class_@GDScript_method_range:
  581. .. rst-class:: classref-method
  582. :ref:`Array<class_Array>` **range** **(** ... **)** |vararg|
  583. Returns an array with the given range. :ref:`range<class_@GDScript_method_range>` can be called in three ways:
  584. \ ``range(n: int)``: Starts from 0, increases by steps of 1, and stops *before* ``n``. The argument ``n`` is **exclusive**.
  585. \ ``range(b: int, n: int)``: Starts from ``b``, increases by steps of 1, and stops *before* ``n``. The arguments ``b`` and ``n`` are **inclusive** and **exclusive**, respectively.
  586. \ ``range(b: int, n: int, s: int)``: Starts from ``b``, increases/decreases by steps of ``s``, and stops *before* ``n``. The arguments ``b`` and ``n`` are **inclusive** and **exclusive**, respectively. The argument ``s`` **can** be negative, but not ``0``. If ``s`` is ``0``, an error message is printed.
  587. \ :ref:`range<class_@GDScript_method_range>` converts all arguments to :ref:`int<class_int>` before processing.
  588. \ **Note:** Returns an empty array if no value meets the value constraint (e.g. ``range(2, 5, -1)`` or ``range(5, 5, 1)``).
  589. Examples:
  590. ::
  591. print(range(4)) # Prints [0, 1, 2, 3]
  592. print(range(2, 5)) # Prints [2, 3, 4]
  593. print(range(0, 6, 2)) # Prints [0, 2, 4]
  594. print(range(4, 1, -1)) # Prints [4, 3, 2]
  595. To iterate over an :ref:`Array<class_Array>` backwards, use:
  596. ::
  597. var array = [3, 6, 9]
  598. for i in range(array.size() - 1, -1, -1):
  599. print(array[i])
  600. Output:
  601. ::
  602. 9
  603. 6
  604. 3
  605. To iterate over :ref:`float<class_float>`, convert them in the loop.
  606. ::
  607. for i in range (3, 0, -1):
  608. print(i / 10.0)
  609. Output:
  610. ::
  611. 0.3
  612. 0.2
  613. 0.1
  614. .. rst-class:: classref-item-separator
  615. ----
  616. .. _class_@GDScript_method_type_exists:
  617. .. rst-class:: classref-method
  618. :ref:`bool<class_bool>` **type_exists** **(** :ref:`StringName<class_StringName>` type **)**
  619. Returns ``true`` if the given :ref:`Object<class_Object>`-derived class exists in :ref:`ClassDB<class_ClassDB>`. Note that :ref:`Variant<class_Variant>` data types are not registered in :ref:`ClassDB<class_ClassDB>`.
  620. ::
  621. type_exists("Sprite2D") # Returns true
  622. type_exists("NonExistentClass") # Returns false
  623. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  624. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  625. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  626. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  627. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  628. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  629. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`