[email protected] 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/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 utility functions and annotations accessible from any script written in GDScript.
  14. For the list of global functions and constants that can be accessed in any scripting language, 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>`\ (\ r8\: :ref:`int<class_int>`, g8\: :ref:`int<class_int>`, b8\: :ref:`int<class_int>`, a8\: :ref:`int<class_int>` = 255\ ) |
  26. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | |void| | :ref:`assert<class_@GDScript_method_assert>`\ (\ condition\: :ref:`bool<class_bool>`, message\: :ref:`String<class_String>` = ""\ ) |
  28. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`String<class_String>` | :ref:`char<class_@GDScript_method_char>`\ (\ code\: :ref:`int<class_int>`\ ) |
  30. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Variant<class_Variant>` | :ref:`convert<class_@GDScript_method_convert>`\ (\ what\: :ref:`Variant<class_Variant>`, type\: :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`\ ) |
  32. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Object<class_Object>` | :ref:`dict_to_inst<class_@GDScript_method_dict_to_inst>`\ (\ dictionary\: :ref:`Dictionary<class_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>`\ (\ instance\: :ref:`Object<class_Object>`\ ) |
  38. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`is_instance_of<class_@GDScript_method_is_instance_of>`\ (\ value\: :ref:`Variant<class_Variant>`, type\: :ref:`Variant<class_Variant>`\ ) |
  40. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`int<class_int>` | :ref:`len<class_@GDScript_method_len>`\ (\ var\: :ref:`Variant<class_Variant>`\ ) |
  42. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Resource<class_Resource>` | :ref:`load<class_@GDScript_method_load>`\ (\ path\: :ref:`String<class_String>`\ ) |
  44. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`int<class_int>` | :ref:`ord<class_@GDScript_method_ord>`\ (\ char\: :ref:`String<class_String>`\ ) |
  46. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Resource<class_Resource>` | :ref:`preload<class_@GDScript_method_preload>`\ (\ path\: :ref:`String<class_String>`\ ) |
  48. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | |void| | :ref:`print_debug<class_@GDScript_method_print_debug>`\ (\ ...\ ) |vararg| |
  50. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | |void| | :ref:`print_stack<class_@GDScript_method_print_stack>`\ (\ ) |
  52. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Array<class_Array>` | :ref:`range<class_@GDScript_method_range>`\ (\ ...\ ) |vararg| |
  54. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`type_exists<class_@GDScript_method_type_exists>`\ (\ type\: :ref:`StringName<class_StringName>`\ ) |
  56. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. .. rst-class:: classref-section-separator
  58. ----
  59. .. rst-class:: classref-descriptions-group
  60. Constants
  61. ---------
  62. .. _class_@GDScript_constant_PI:
  63. .. rst-class:: classref-constant
  64. **PI** = ``3.14159265358979`` :ref:`🔗<class_@GDScript_constant_PI>`
  65. 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.
  66. .. _class_@GDScript_constant_TAU:
  67. .. rst-class:: classref-constant
  68. **TAU** = ``6.28318530717959`` :ref:`🔗<class_@GDScript_constant_TAU>`
  69. The circle constant, the circumference of the unit circle in radians. This is equivalent to ``PI * 2``, or 360 degrees in rotations.
  70. .. _class_@GDScript_constant_INF:
  71. .. rst-class:: classref-constant
  72. **INF** = ``inf`` :ref:`🔗<class_@GDScript_constant_INF>`
  73. 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``).
  74. \ **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.
  75. .. _class_@GDScript_constant_NAN:
  76. .. rst-class:: classref-constant
  77. **NAN** = ``nan`` :ref:`🔗<class_@GDScript_constant_NAN>`
  78. "Not a Number", an invalid floating-point value. It is returned by some invalid operations, such as dividing floating-point ``0.0`` by ``0.0``.
  79. \ :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``). Due to this, you must use :ref:`@GlobalScope.is_nan()<class_@GlobalScope_method_is_nan>` to check whether a number is equal to :ref:`NAN<class_@GDScript_constant_NAN>`.
  80. \ **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.
  81. .. rst-class:: classref-section-separator
  82. ----
  83. .. rst-class:: classref-descriptions-group
  84. Annotations
  85. -----------
  86. .. _class_@GDScript_annotation_@abstract:
  87. .. rst-class:: classref-annotation
  88. **@abstract**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@abstract>`
  89. Marks a class or a method as abstract.
  90. An abstract class is a class that cannot be instantiated directly. Instead, it is meant to be inherited by other classes. Attempting to instantiate an abstract class will result in an error.
  91. An abstract method is a method that has no implementation. Therefore, a newline or a semicolon is expected after the function header. This defines a contract that inheriting classes must conform to, because the method signature must be compatible when overriding.
  92. Inheriting classes must either provide implementations for all abstract methods, or the inheriting class must be marked as abstract. If a class has at least one abstract method (either its own or an unimplemented inherited one), then it must also be marked as abstract. However, the reverse is not true: an abstract class is allowed to have no abstract methods.
  93. ::
  94. @abstract class Shape:
  95. @abstract func draw()
  96. class Circle extends Shape:
  97. func draw():
  98. print("Drawing a circle.")
  99. class Square extends Shape:
  100. func draw():
  101. print("Drawing a square.")
  102. .. rst-class:: classref-item-separator
  103. ----
  104. .. _class_@GDScript_annotation_@export:
  105. .. rst-class:: classref-annotation
  106. **@export**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export>`
  107. 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.
  108. ::
  109. extends Node
  110. enum Direction {LEFT, RIGHT, UP, DOWN}
  111. # Built-in types.
  112. @export var string = ""
  113. @export var int_number = 5
  114. @export var float_number: float = 5
  115. # Enums.
  116. @export var type: Variant.Type
  117. @export var format: Image.Format
  118. @export var direction: Direction
  119. # Resources.
  120. @export var image: Image
  121. @export var custom_resource: CustomResource
  122. # Nodes.
  123. @export var node: Node
  124. @export var custom_node: CustomNode
  125. # Typed arrays.
  126. @export var int_array: Array[int]
  127. @export var direction_array: Array[Direction]
  128. @export var image_array: Array[Image]
  129. @export var node_array: Array[Node]
  130. \ **Note:** Custom resources and nodes should be registered as global classes using ``class_name``, since the Inspector currently only supports global classes. Otherwise, a less specific type will be exported instead.
  131. \ **Note:** Node export is only supported in :ref:`Node<class_Node>`-derived classes and has a number of other limitations.
  132. .. rst-class:: classref-item-separator
  133. ----
  134. .. _class_@GDScript_annotation_@export_category:
  135. .. rst-class:: classref-annotation
  136. **@export_category**\ (\ name\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_annotation_@export_category>`
  137. Define a new category for the following exported properties. This helps to organize properties in the Inspector dock.
  138. See also :ref:`@GlobalScope.PROPERTY_USAGE_CATEGORY<class_@GlobalScope_constant_PROPERTY_USAGE_CATEGORY>`.
  139. ::
  140. @export_category("Statistics")
  141. @export var hp = 30
  142. @export var speed = 1.25
  143. \ **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.
  144. .. rst-class:: classref-item-separator
  145. ----
  146. .. _class_@GDScript_annotation_@export_color_no_alpha:
  147. .. rst-class:: classref-annotation
  148. **@export_color_no_alpha**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_color_no_alpha>`
  149. Export a :ref:`Color<class_Color>`, :ref:`Array<class_Array>`\ \[:ref:`Color<class_Color>`\ \], or :ref:`PackedColorArray<class_PackedColorArray>` property without allowing its transparency (:ref:`Color.a<class_Color_property_a>`) to be edited.
  150. See also :ref:`@GlobalScope.PROPERTY_HINT_COLOR_NO_ALPHA<class_@GlobalScope_constant_PROPERTY_HINT_COLOR_NO_ALPHA>`.
  151. ::
  152. @export_color_no_alpha var dye_color: Color
  153. @export_color_no_alpha var dye_colors: Array[Color]
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_@GDScript_annotation_@export_custom:
  157. .. rst-class:: classref-annotation
  158. **@export_custom**\ (\ hint\: :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>`, hint_string\: :ref:`String<class_String>`, usage\: |bitfield|\[:ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>`\] = 6\ ) :ref:`🔗<class_@GDScript_annotation_@export_custom>`
  159. Allows you to set a custom hint, hint string, and usage flags for the exported property. Note that there's no validation done in GDScript, it will just pass the parameters to the editor.
  160. ::
  161. @export_custom(PROPERTY_HINT_NONE, "suffix:m") var suffix: Vector3
  162. \ **Note:** Regardless of the ``usage`` value, the :ref:`@GlobalScope.PROPERTY_USAGE_SCRIPT_VARIABLE<class_@GlobalScope_constant_PROPERTY_USAGE_SCRIPT_VARIABLE>` flag is always added, as with any explicitly declared script variable.
  163. .. rst-class:: classref-item-separator
  164. ----
  165. .. _class_@GDScript_annotation_@export_dir:
  166. .. rst-class:: classref-annotation
  167. **@export_dir**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_dir>`
  168. Export a :ref:`String<class_String>`, :ref:`Array<class_Array>`\ \[:ref:`String<class_String>`\ \], or :ref:`PackedStringArray<class_PackedStringArray>` 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.
  169. See also :ref:`@GlobalScope.PROPERTY_HINT_DIR<class_@GlobalScope_constant_PROPERTY_HINT_DIR>`.
  170. ::
  171. @export_dir var sprite_folder_path: String
  172. @export_dir var sprite_folder_paths: Array[String]
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_@GDScript_annotation_@export_enum:
  176. .. rst-class:: classref-annotation
  177. **@export_enum**\ (\ names\: :ref:`String<class_String>`, ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@export_enum>`
  178. Export an :ref:`int<class_int>`, :ref:`String<class_String>`, :ref:`Array<class_Array>`\ \[:ref:`int<class_int>`\ \], :ref:`Array<class_Array>`\ \[:ref:`String<class_String>`\ \], :ref:`PackedByteArray<class_PackedByteArray>`, :ref:`PackedInt32Array<class_PackedInt32Array>`, :ref:`PackedInt64Array<class_PackedInt64Array>`, or :ref:`PackedStringArray<class_PackedStringArray>` property as an enumerated list of options (or an array 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.
  179. See also :ref:`@GlobalScope.PROPERTY_HINT_ENUM<class_@GlobalScope_constant_PROPERTY_HINT_ENUM>`.
  180. ::
  181. @export_enum("Warrior", "Magician", "Thief") var character_class: int
  182. @export_enum("Slow:30", "Average:60", "Very Fast:200") var character_speed: int
  183. @export_enum("Rebecca", "Mary", "Leah") var character_name: String
  184. @export_enum("Sword", "Spear", "Mace") var character_items: Array[int]
  185. @export_enum("double_jump", "climb", "dash") var character_skills: Array[String]
  186. If you want to set an initial value, you must specify it explicitly:
  187. ::
  188. @export_enum("Rebecca", "Mary", "Leah") var character_name: String = "Rebecca"
  189. If you want to use named GDScript enums, then use :ref:`@export<class_@GDScript_annotation_@export>` instead:
  190. ::
  191. enum CharacterName {REBECCA, MARY, LEAH}
  192. @export var character_name: CharacterName
  193. enum CharacterItem {SWORD, SPEAR, MACE}
  194. @export var character_items: Array[CharacterItem]
  195. .. rst-class:: classref-item-separator
  196. ----
  197. .. _class_@GDScript_annotation_@export_exp_easing:
  198. .. rst-class:: classref-annotation
  199. **@export_exp_easing**\ (\ hints\: :ref:`String<class_String>` = "", ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@export_exp_easing>`
  200. 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.
  201. See also :ref:`@GlobalScope.PROPERTY_HINT_EXP_EASING<class_@GlobalScope_constant_PROPERTY_HINT_EXP_EASING>`.
  202. ::
  203. @export_exp_easing var transition_speed
  204. @export_exp_easing("attenuation") var fading_attenuation
  205. @export_exp_easing("positive_only") var effect_power
  206. @export_exp_easing var speeds: Array[float]
  207. .. rst-class:: classref-item-separator
  208. ----
  209. .. _class_@GDScript_annotation_@export_file:
  210. .. rst-class:: classref-annotation
  211. **@export_file**\ (\ filter\: :ref:`String<class_String>` = "", ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@export_file>`
  212. Export a :ref:`String<class_String>`, :ref:`Array<class_Array>`\ \[:ref:`String<class_String>`\ \], or :ref:`PackedStringArray<class_PackedStringArray>` 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.
  213. If ``filter`` is provided, only matching files will be available for picking.
  214. See also :ref:`@GlobalScope.PROPERTY_HINT_FILE<class_@GlobalScope_constant_PROPERTY_HINT_FILE>`.
  215. ::
  216. @export_file var sound_effect_path: String
  217. @export_file("*.txt") var notes_path: String
  218. @export_file var level_paths: Array[String]
  219. \ **Note:** The file will be stored and referenced as UID, if available. This ensures that the reference is valid even when the file is moved. You can use :ref:`ResourceUID<class_ResourceUID>` methods to convert it to path.
  220. .. rst-class:: classref-item-separator
  221. ----
  222. .. _class_@GDScript_annotation_@export_file_path:
  223. .. rst-class:: classref-annotation
  224. **@export_file_path**\ (\ filter\: :ref:`String<class_String>` = "", ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@export_file_path>`
  225. Same as :ref:`@export_file<class_@GDScript_annotation_@export_file>`, except the file will be stored as a raw path. This means that it may become invalid when the file is moved. If you are exporting a :ref:`Resource<class_Resource>` path, consider using :ref:`@export_file<class_@GDScript_annotation_@export_file>` instead.
  226. .. rst-class:: classref-item-separator
  227. ----
  228. .. _class_@GDScript_annotation_@export_flags:
  229. .. rst-class:: classref-annotation
  230. **@export_flags**\ (\ names\: :ref:`String<class_String>`, ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@export_flags>`
  231. 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.
  232. See also :ref:`@GlobalScope.PROPERTY_HINT_FLAGS<class_@GlobalScope_constant_PROPERTY_HINT_FLAGS>`.
  233. ::
  234. @export_flags("Fire", "Water", "Earth", "Wind") var spell_elements = 0
  235. You can add explicit values using a colon:
  236. ::
  237. @export_flags("Self:4", "Allies:8", "Foes:16") var spell_targets = 0
  238. You can also combine several flags:
  239. ::
  240. @export_flags("Self:4", "Allies:8", "Self and Allies:12", "Foes:16")
  241. var spell_targets = 0
  242. \ **Note:** A flag value must be at least ``1`` and at most ``2 ** 32 - 1``.
  243. \ **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.
  244. ::
  245. @export_flags("A:16", "B", "C") var x
  246. You can also use the annotation on :ref:`Array<class_Array>`\ \[:ref:`int<class_int>`\ \], :ref:`PackedByteArray<class_PackedByteArray>`, :ref:`PackedInt32Array<class_PackedInt32Array>`, and :ref:`PackedInt64Array<class_PackedInt64Array>`\
  247. ::
  248. @export_flags("Fire", "Water", "Earth", "Wind") var phase_elements: Array[int]
  249. .. rst-class:: classref-item-separator
  250. ----
  251. .. _class_@GDScript_annotation_@export_flags_2d_navigation:
  252. .. rst-class:: classref-annotation
  253. **@export_flags_2d_navigation**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_2d_navigation>`
  254. 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>`.
  255. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_2D_NAVIGATION<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_2D_NAVIGATION>`.
  256. ::
  257. @export_flags_2d_navigation var navigation_layers: int
  258. @export_flags_2d_navigation var navigation_layers_array: Array[int]
  259. .. rst-class:: classref-item-separator
  260. ----
  261. .. _class_@GDScript_annotation_@export_flags_2d_physics:
  262. .. rst-class:: classref-annotation
  263. **@export_flags_2d_physics**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_2d_physics>`
  264. 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>`.
  265. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_2D_PHYSICS<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_2D_PHYSICS>`.
  266. ::
  267. @export_flags_2d_physics var physics_layers: int
  268. @export_flags_2d_physics var physics_layers_array: Array[int]
  269. .. rst-class:: classref-item-separator
  270. ----
  271. .. _class_@GDScript_annotation_@export_flags_2d_render:
  272. .. rst-class:: classref-annotation
  273. **@export_flags_2d_render**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_2d_render>`
  274. 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>`.
  275. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_2D_RENDER<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_2D_RENDER>`.
  276. ::
  277. @export_flags_2d_render var render_layers: int
  278. @export_flags_2d_render var render_layers_array: Array[int]
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_@GDScript_annotation_@export_flags_3d_navigation:
  282. .. rst-class:: classref-annotation
  283. **@export_flags_3d_navigation**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_3d_navigation>`
  284. 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>`.
  285. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_3D_NAVIGATION<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_3D_NAVIGATION>`.
  286. ::
  287. @export_flags_3d_navigation var navigation_layers: int
  288. @export_flags_3d_navigation var navigation_layers_array: Array[int]
  289. .. rst-class:: classref-item-separator
  290. ----
  291. .. _class_@GDScript_annotation_@export_flags_3d_physics:
  292. .. rst-class:: classref-annotation
  293. **@export_flags_3d_physics**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_3d_physics>`
  294. 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>`.
  295. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_3D_PHYSICS<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_3D_PHYSICS>`.
  296. ::
  297. @export_flags_3d_physics var physics_layers: int
  298. @export_flags_3d_physics var physics_layers_array: Array[int]
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_@GDScript_annotation_@export_flags_3d_render:
  302. .. rst-class:: classref-annotation
  303. **@export_flags_3d_render**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_3d_render>`
  304. 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>`.
  305. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_3D_RENDER<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_3D_RENDER>`.
  306. ::
  307. @export_flags_3d_render var render_layers: int
  308. @export_flags_3d_render var render_layers_array: Array[int]
  309. .. rst-class:: classref-item-separator
  310. ----
  311. .. _class_@GDScript_annotation_@export_flags_avoidance:
  312. .. rst-class:: classref-annotation
  313. **@export_flags_avoidance**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_avoidance>`
  314. 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>`.
  315. See also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_AVOIDANCE<class_@GlobalScope_constant_PROPERTY_HINT_LAYERS_AVOIDANCE>`.
  316. ::
  317. @export_flags_avoidance var avoidance_layers: int
  318. @export_flags_avoidance var avoidance_layers_array: Array[int]
  319. .. rst-class:: classref-item-separator
  320. ----
  321. .. _class_@GDScript_annotation_@export_global_dir:
  322. .. rst-class:: classref-annotation
  323. **@export_global_dir**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_global_dir>`
  324. Export a :ref:`String<class_String>`, :ref:`Array<class_Array>`\ \[:ref:`String<class_String>`\ \], or :ref:`PackedStringArray<class_PackedStringArray>` 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.
  325. See also :ref:`@GlobalScope.PROPERTY_HINT_GLOBAL_DIR<class_@GlobalScope_constant_PROPERTY_HINT_GLOBAL_DIR>`.
  326. ::
  327. @export_global_dir var sprite_folder_path: String
  328. @export_global_dir var sprite_folder_paths: Array[String]
  329. .. rst-class:: classref-item-separator
  330. ----
  331. .. _class_@GDScript_annotation_@export_global_file:
  332. .. rst-class:: classref-annotation
  333. **@export_global_file**\ (\ filter\: :ref:`String<class_String>` = "", ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@export_global_file>`
  334. Export a :ref:`String<class_String>`, :ref:`Array<class_Array>`\ \[:ref:`String<class_String>`\ \], or :ref:`PackedStringArray<class_PackedStringArray>` 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.
  335. If ``filter`` is provided, only matching files will be available for picking.
  336. See also :ref:`@GlobalScope.PROPERTY_HINT_GLOBAL_FILE<class_@GlobalScope_constant_PROPERTY_HINT_GLOBAL_FILE>`.
  337. ::
  338. @export_global_file var sound_effect_path: String
  339. @export_global_file("*.txt") var notes_path: String
  340. @export_global_file var multiple_paths: Array[String]
  341. .. rst-class:: classref-item-separator
  342. ----
  343. .. _class_@GDScript_annotation_@export_group:
  344. .. rst-class:: classref-annotation
  345. **@export_group**\ (\ name\: :ref:`String<class_String>`, prefix\: :ref:`String<class_String>` = ""\ ) :ref:`🔗<class_@GDScript_annotation_@export_group>`
  346. 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.
  347. 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("", "")``.
  348. Groups cannot be nested, use :ref:`@export_subgroup<class_@GDScript_annotation_@export_subgroup>` to add subgroups within groups.
  349. See also :ref:`@GlobalScope.PROPERTY_USAGE_GROUP<class_@GlobalScope_constant_PROPERTY_USAGE_GROUP>`.
  350. ::
  351. @export_group("Racer Properties")
  352. @export var nickname = "Nick"
  353. @export var age = 26
  354. @export_group("Car Properties", "car_")
  355. @export var car_label = "Speedy"
  356. @export var car_number = 3
  357. @export_group("", "")
  358. @export var ungrouped_number = 3
  359. .. rst-class:: classref-item-separator
  360. ----
  361. .. _class_@GDScript_annotation_@export_multiline:
  362. .. rst-class:: classref-annotation
  363. **@export_multiline**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_multiline>`
  364. Export a :ref:`String<class_String>`, :ref:`Array<class_Array>`\ \[:ref:`String<class_String>`\ \], :ref:`PackedStringArray<class_PackedStringArray>`, :ref:`Dictionary<class_Dictionary>` or :ref:`Array<class_Array>`\ \[:ref:`Dictionary<class_Dictionary>`\ \] 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.
  365. See also :ref:`@GlobalScope.PROPERTY_HINT_MULTILINE_TEXT<class_@GlobalScope_constant_PROPERTY_HINT_MULTILINE_TEXT>`.
  366. ::
  367. @export_multiline var character_biography
  368. @export_multiline var npc_dialogs: Array[String]
  369. .. rst-class:: classref-item-separator
  370. ----
  371. .. _class_@GDScript_annotation_@export_node_path:
  372. .. rst-class:: classref-annotation
  373. **@export_node_path**\ (\ type\: :ref:`String<class_String>` = "", ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@export_node_path>`
  374. Export a :ref:`NodePath<class_NodePath>` or :ref:`Array<class_Array>`\ \[:ref:`NodePath<class_NodePath>`\ \] property with a filter for allowed node types.
  375. See also :ref:`@GlobalScope.PROPERTY_HINT_NODE_PATH_VALID_TYPES<class_@GlobalScope_constant_PROPERTY_HINT_NODE_PATH_VALID_TYPES>`.
  376. ::
  377. @export_node_path("Button", "TouchScreenButton") var some_button
  378. @export_node_path("Button", "TouchScreenButton") var many_buttons: Array[NodePath]
  379. \ **Note:** The type must be a native class or a globally registered script (using the ``class_name`` keyword) that inherits :ref:`Node<class_Node>`.
  380. .. rst-class:: classref-item-separator
  381. ----
  382. .. _class_@GDScript_annotation_@export_placeholder:
  383. .. rst-class:: classref-annotation
  384. **@export_placeholder**\ (\ placeholder\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_annotation_@export_placeholder>`
  385. Export a :ref:`String<class_String>`, :ref:`Array<class_Array>`\ \[:ref:`String<class_String>`\ \], or :ref:`PackedStringArray<class_PackedStringArray>` property with a placeholder text displayed in the editor widget when no value is present.
  386. See also :ref:`@GlobalScope.PROPERTY_HINT_PLACEHOLDER_TEXT<class_@GlobalScope_constant_PROPERTY_HINT_PLACEHOLDER_TEXT>`.
  387. ::
  388. @export_placeholder("Name in lowercase") var character_id: String
  389. @export_placeholder("Name in lowercase") var friend_ids: Array[String]
  390. .. rst-class:: classref-item-separator
  391. ----
  392. .. _class_@GDScript_annotation_@export_range:
  393. .. rst-class:: classref-annotation
  394. **@export_range**\ (\ min\: :ref:`float<class_float>`, max\: :ref:`float<class_float>`, step\: :ref:`float<class_float>` = 1.0, extra_hints\: :ref:`String<class_String>` = "", ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@export_range>`
  395. Export an :ref:`int<class_int>`, :ref:`float<class_float>`, :ref:`Array<class_Array>`\ \[:ref:`int<class_int>`\ \], :ref:`Array<class_Array>`\ \[:ref:`float<class_float>`\ \], :ref:`PackedByteArray<class_PackedByteArray>`, :ref:`PackedInt32Array<class_PackedInt32Array>`, :ref:`PackedInt64Array<class_PackedInt64Array>`, :ref:`PackedFloat32Array<class_PackedFloat32Array>`, or :ref:`PackedFloat64Array<class_PackedFloat64Array>` 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 :ref:`EditorSettings.interface/inspector/default_float_step<class_EditorSettings_property_interface/inspector/default_float_step>` setting.
  396. 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 ``"prefer_slider"`` hint will make integer values use the slider instead of arrows for editing, while ``"hide_control"`` will hide the element controlling the value of the editor widget.
  397. Hints also allow to indicate the units for the edited value. Using ``"radians_as_degrees"`` you can specify that the actual value is in radians, but should be displayed in degrees in the Inspector dock (the range values are also in degrees). ``"degrees"`` allows to add a degree sign as a unit suffix (the value is unchanged). Finally, a custom suffix can be provided using ``"suffix:unit"``, where "unit" can be any string.
  398. See also :ref:`@GlobalScope.PROPERTY_HINT_RANGE<class_@GlobalScope_constant_PROPERTY_HINT_RANGE>`.
  399. ::
  400. @export_range(0, 20) var number
  401. @export_range(-10, 20) var number
  402. @export_range(-10, 20, 0.2) var number: float
  403. @export_range(0, 20) var numbers: Array[float]
  404. @export_range(0, 100, 1, "or_greater") var power_percent
  405. @export_range(0, 100, 1, "or_greater", "or_less") var health_delta
  406. @export_range(-180, 180, 0.001, "radians_as_degrees") var angle_radians
  407. @export_range(0, 360, 1, "degrees") var angle_degrees
  408. @export_range(-8, 8, 2, "suffix:px") var target_offset
  409. .. rst-class:: classref-item-separator
  410. ----
  411. .. _class_@GDScript_annotation_@export_storage:
  412. .. rst-class:: classref-annotation
  413. **@export_storage**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_storage>`
  414. Export a property with :ref:`@GlobalScope.PROPERTY_USAGE_STORAGE<class_@GlobalScope_constant_PROPERTY_USAGE_STORAGE>` flag. The property is not displayed in the editor, but it is serialized and stored in the scene or resource file. This can be useful for :ref:`@tool<class_@GDScript_annotation_@tool>` scripts. Also the property value is copied when :ref:`Resource.duplicate()<class_Resource_method_duplicate>` or :ref:`Node.duplicate()<class_Node_method_duplicate>` is called, unlike non-exported variables.
  415. ::
  416. var a # Not stored in the file, not displayed in the editor.
  417. @export_storage var b # Stored in the file, not displayed in the editor.
  418. @export var c: int # Stored in the file, displayed in the editor.
  419. .. rst-class:: classref-item-separator
  420. ----
  421. .. _class_@GDScript_annotation_@export_subgroup:
  422. .. rst-class:: classref-annotation
  423. **@export_subgroup**\ (\ name\: :ref:`String<class_String>`, prefix\: :ref:`String<class_String>` = ""\ ) :ref:`🔗<class_@GDScript_annotation_@export_subgroup>`
  424. 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>`.
  425. See also :ref:`@GlobalScope.PROPERTY_USAGE_SUBGROUP<class_@GlobalScope_constant_PROPERTY_USAGE_SUBGROUP>`.
  426. ::
  427. @export_group("Racer Properties")
  428. @export var nickname = "Nick"
  429. @export var age = 26
  430. @export_subgroup("Car Properties", "car_")
  431. @export var car_label = "Speedy"
  432. @export var car_number = 3
  433. \ **Note:** Subgroups cannot be nested, but you can use the slash separator (``/``) to achieve the desired effect:
  434. ::
  435. @export_group("Car Properties")
  436. @export_subgroup("Wheels", "wheel_")
  437. @export_subgroup("Wheels/Front", "front_wheel_")
  438. @export var front_wheel_strength = 10
  439. @export var front_wheel_mobility = 5
  440. @export_subgroup("Wheels/Rear", "rear_wheel_")
  441. @export var rear_wheel_strength = 8
  442. @export var rear_wheel_mobility = 3
  443. @export_subgroup("Wheels", "wheel_")
  444. @export var wheel_material: PhysicsMaterial
  445. .. rst-class:: classref-item-separator
  446. ----
  447. .. _class_@GDScript_annotation_@export_tool_button:
  448. .. rst-class:: classref-annotation
  449. **@export_tool_button**\ (\ text\: :ref:`String<class_String>`, icon\: :ref:`String<class_String>` = ""\ ) :ref:`🔗<class_@GDScript_annotation_@export_tool_button>`
  450. Export a :ref:`Callable<class_Callable>` property as a clickable button with the label ``text``. When the button is pressed, the callable is called.
  451. If ``icon`` is specified, it is used to fetch an icon for the button via :ref:`Control.get_theme_icon()<class_Control_method_get_theme_icon>`, from the ``"EditorIcons"`` theme type. If ``icon`` is omitted, the default ``"Callable"`` icon is used instead.
  452. Consider using the :ref:`EditorUndoRedoManager<class_EditorUndoRedoManager>` to allow the action to be reverted safely.
  453. See also :ref:`@GlobalScope.PROPERTY_HINT_TOOL_BUTTON<class_@GlobalScope_constant_PROPERTY_HINT_TOOL_BUTTON>`.
  454. ::
  455. @tool
  456. extends Sprite2D
  457. @export_tool_button("Hello") var hello_action = hello
  458. @export_tool_button("Randomize the color!", "ColorRect")
  459. var randomize_color_action = randomize_color
  460. func hello():
  461. print("Hello world!")
  462. func randomize_color():
  463. var undo_redo = EditorInterface.get_editor_undo_redo()
  464. undo_redo.create_action("Randomized Sprite2D Color")
  465. undo_redo.add_do_property(self, &"self_modulate", Color(randf(), randf(), randf()))
  466. undo_redo.add_undo_property(self, &"self_modulate", self_modulate)
  467. undo_redo.commit_action()
  468. \ **Note:** The property is exported without the :ref:`@GlobalScope.PROPERTY_USAGE_STORAGE<class_@GlobalScope_constant_PROPERTY_USAGE_STORAGE>` flag because a :ref:`Callable<class_Callable>` cannot be properly serialized and stored in a file.
  469. \ **Note:** In an exported project neither :ref:`EditorInterface<class_EditorInterface>` nor :ref:`EditorUndoRedoManager<class_EditorUndoRedoManager>` exist, which may cause some scripts to break. To prevent this, you can use :ref:`Engine.get_singleton()<class_Engine_method_get_singleton>` and omit the static type from the variable declaration:
  470. ::
  471. var undo_redo = Engine.get_singleton(&"EditorInterface").get_editor_undo_redo()
  472. \ **Note:** Avoid storing lambda callables in member variables of :ref:`RefCounted<class_RefCounted>`-based classes (e.g. resources), as this can lead to memory leaks. Use only method callables and optionally :ref:`Callable.bind()<class_Callable_method_bind>` or :ref:`Callable.unbind()<class_Callable_method_unbind>`.
  473. .. rst-class:: classref-item-separator
  474. ----
  475. .. _class_@GDScript_annotation_@icon:
  476. .. rst-class:: classref-annotation
  477. **@icon**\ (\ icon_path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_annotation_@icon>`
  478. Add a custom icon to the current script. 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.
  479. ::
  480. @icon("res://path/to/class/icon.svg")
  481. \ **Note:** Only the script can have a custom icon. Inner classes are not supported.
  482. \ **Note:** As annotations describe their subject, the :ref:`@icon<class_@GDScript_annotation_@icon>` annotation must be placed before the class definition and inheritance.
  483. \ **Note:** Unlike most other annotations, the argument of the :ref:`@icon<class_@GDScript_annotation_@icon>` annotation must be a string literal (constant expressions are not supported).
  484. .. rst-class:: classref-item-separator
  485. ----
  486. .. _class_@GDScript_annotation_@onready:
  487. .. rst-class:: classref-annotation
  488. **@onready**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@onready>`
  489. 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_private_method__init>`), and instead are computed and stored right before :ref:`Node._ready()<class_Node_private_method__ready>`.
  490. ::
  491. @onready var character_name = $Label
  492. .. rst-class:: classref-item-separator
  493. ----
  494. .. _class_@GDScript_annotation_@rpc:
  495. .. rst-class:: classref-annotation
  496. **@rpc**\ (\ mode\: :ref:`String<class_String>` = "authority", sync\: :ref:`String<class_String>` = "call_remote", transfer_mode\: :ref:`String<class_String>` = "unreliable", transfer_channel\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_@GDScript_annotation_@rpc>`
  497. Mark the following method for remote procedure calls. See :doc:`High-level multiplayer <../tutorials/networking/high_level_multiplayer>`.
  498. 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.
  499. 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``.
  500. 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>`.
  501. The ``transfer_channel`` defines the channel of the underlying :ref:`MultiplayerPeer<class_MultiplayerPeer>`. See :ref:`MultiplayerPeer.transfer_channel<class_MultiplayerPeer_property_transfer_channel>`.
  502. 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).
  503. ::
  504. @rpc
  505. func fn(): pass
  506. @rpc("any_peer", "unreliable_ordered")
  507. func fn_update_pos(): pass
  508. @rpc("authority", "call_remote", "unreliable", 0) # Equivalent to @rpc
  509. func fn_default(): pass
  510. \ **Note:** Methods annotated with :ref:`@rpc<class_@GDScript_annotation_@rpc>` cannot receive objects which define required parameters in :ref:`Object._init()<class_Object_private_method__init>`. See :ref:`Object._init()<class_Object_private_method__init>` for more details.
  511. .. rst-class:: classref-item-separator
  512. ----
  513. .. _class_@GDScript_annotation_@static_unload:
  514. .. rst-class:: classref-annotation
  515. **@static_unload**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@static_unload>`
  516. 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.
  517. \ **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.
  518. \ **Warning:** Currently, due to a bug, scripts are never freed, even if :ref:`@static_unload<class_@GDScript_annotation_@static_unload>` annotation is used.
  519. .. rst-class:: classref-item-separator
  520. ----
  521. .. _class_@GDScript_annotation_@tool:
  522. .. rst-class:: classref-annotation
  523. **@tool**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@tool>`
  524. 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>`.
  525. ::
  526. @tool
  527. extends Node
  528. \ **Note:** As annotations describe their subject, the :ref:`@tool<class_@GDScript_annotation_@tool>` annotation must be placed before the class definition and inheritance.
  529. .. rst-class:: classref-item-separator
  530. ----
  531. .. _class_@GDScript_annotation_@warning_ignore:
  532. .. rst-class:: classref-annotation
  533. **@warning_ignore**\ (\ warning\: :ref:`String<class_String>`, ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@warning_ignore>`
  534. Mark the following statement to ignore the specified ``warning``. See :doc:`GDScript warning system <../tutorials/scripting/gdscript/warning_system>`.
  535. ::
  536. func test():
  537. print("hello")
  538. return
  539. @warning_ignore("unreachable_code")
  540. print("unreachable")
  541. See also :ref:`@warning_ignore_start<class_@GDScript_annotation_@warning_ignore_start>` and :ref:`@warning_ignore_restore<class_@GDScript_annotation_@warning_ignore_restore>`.
  542. .. rst-class:: classref-item-separator
  543. ----
  544. .. _class_@GDScript_annotation_@warning_ignore_restore:
  545. .. rst-class:: classref-annotation
  546. **@warning_ignore_restore**\ (\ warning\: :ref:`String<class_String>`, ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@warning_ignore_restore>`
  547. Stops ignoring the listed warning types after :ref:`@warning_ignore_start<class_@GDScript_annotation_@warning_ignore_start>`. Ignoring the specified warning types will be reset to Project Settings. This annotation can be omitted to ignore the warning types until the end of the file.
  548. \ **Note:** Unlike most other annotations, arguments of the :ref:`@warning_ignore_restore<class_@GDScript_annotation_@warning_ignore_restore>` annotation must be string literals (constant expressions are not supported).
  549. .. rst-class:: classref-item-separator
  550. ----
  551. .. _class_@GDScript_annotation_@warning_ignore_start:
  552. .. rst-class:: classref-annotation
  553. **@warning_ignore_start**\ (\ warning\: :ref:`String<class_String>`, ...\ ) |vararg| :ref:`🔗<class_@GDScript_annotation_@warning_ignore_start>`
  554. Starts ignoring the listed warning types until the end of the file or the :ref:`@warning_ignore_restore<class_@GDScript_annotation_@warning_ignore_restore>` annotation with the given warning type.
  555. ::
  556. func test():
  557. var a = 1 # Warning (if enabled in the Project Settings).
  558. @warning_ignore_start("unused_variable")
  559. var b = 2 # No warning.
  560. var c = 3 # No warning.
  561. @warning_ignore_restore("unused_variable")
  562. var d = 4 # Warning (if enabled in the Project Settings).
  563. \ **Note:** To suppress a single warning, use :ref:`@warning_ignore<class_@GDScript_annotation_@warning_ignore>` instead.
  564. \ **Note:** Unlike most other annotations, arguments of the :ref:`@warning_ignore_start<class_@GDScript_annotation_@warning_ignore_start>` annotation must be string literals (constant expressions are not supported).
  565. .. rst-class:: classref-section-separator
  566. ----
  567. .. rst-class:: classref-descriptions-group
  568. Method Descriptions
  569. -------------------
  570. .. _class_@GDScript_method_Color8:
  571. .. rst-class:: classref-method
  572. :ref:`Color<class_Color>` **Color8**\ (\ r8\: :ref:`int<class_int>`, g8\: :ref:`int<class_int>`, b8\: :ref:`int<class_int>`, a8\: :ref:`int<class_int>` = 255\ ) :ref:`🔗<class_@GDScript_method_Color8>`
  573. **Deprecated:** Use :ref:`Color.from_rgba8()<class_Color_method_from_rgba8>` instead.
  574. 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>`.
  575. ::
  576. var red = Color8(255, 0, 0) # Same as Color(1, 0, 0).
  577. var dark_blue = Color8(0, 0, 51) # Same as Color(0, 0, 0.2).
  578. var my_color = Color8(306, 255, 0, 102) # Same as Color(1.2, 1, 0, 0.4).
  579. \ **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.
  580. .. rst-class:: classref-item-separator
  581. ----
  582. .. _class_@GDScript_method_assert:
  583. .. rst-class:: classref-method
  584. |void| **assert**\ (\ condition\: :ref:`bool<class_bool>`, message\: :ref:`String<class_String>` = ""\ ) :ref:`🔗<class_@GDScript_method_assert>`
  585. 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.
  586. 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.
  587. \ **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.
  588. ::
  589. # Imagine we always want speed to be between 0 and 20.
  590. var speed = -10
  591. assert(speed < 20) # True, the program will continue.
  592. assert(speed >= 0) # False, the program will stop.
  593. assert(speed >= 0 and speed < 20) # You can also combine the two conditional statements in one check.
  594. assert(speed < 20, "the speed limit is 20") # Show a message.
  595. \ **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.
  596. .. rst-class:: classref-item-separator
  597. ----
  598. .. _class_@GDScript_method_char:
  599. .. rst-class:: classref-method
  600. :ref:`String<class_String>` **char**\ (\ code\: :ref:`int<class_int>`\ ) :ref:`🔗<class_@GDScript_method_char>`
  601. Returns a single character (as a :ref:`String<class_String>` of length 1) of the given Unicode code point ``code``.
  602. ::
  603. print(char(65)) # Prints "A"
  604. print(char(129302)) # Prints "🤖" (robot face emoji)
  605. This is the inverse of :ref:`ord()<class_@GDScript_method_ord>`. See also :ref:`String.chr()<class_String_method_chr>` and :ref:`String.unicode_at()<class_String_method_unicode_at>`.
  606. .. rst-class:: classref-item-separator
  607. ----
  608. .. _class_@GDScript_method_convert:
  609. .. rst-class:: classref-method
  610. :ref:`Variant<class_Variant>` **convert**\ (\ what\: :ref:`Variant<class_Variant>`, type\: :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`\ ) :ref:`🔗<class_@GDScript_method_convert>`
  611. **Deprecated:** Use :ref:`@GlobalScope.type_convert()<class_@GlobalScope_method_type_convert>` instead.
  612. Converts ``what`` to ``type`` in the best way possible. The ``type`` uses the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` values.
  613. ::
  614. var a = [4, 2.5, 1.2]
  615. print(a is Array) # Prints true
  616. var b = convert(a, TYPE_PACKED_BYTE_ARRAY)
  617. print(b) # Prints [4, 2, 1]
  618. print(b is Array) # Prints false
  619. .. rst-class:: classref-item-separator
  620. ----
  621. .. _class_@GDScript_method_dict_to_inst:
  622. .. rst-class:: classref-method
  623. :ref:`Object<class_Object>` **dict_to_inst**\ (\ dictionary\: :ref:`Dictionary<class_Dictionary>`\ ) :ref:`🔗<class_@GDScript_method_dict_to_inst>`
  624. **Deprecated:** Consider using :ref:`JSON.to_native()<class_JSON_method_to_native>` or :ref:`Object.get_property_list()<class_Object_method_get_property_list>` instead.
  625. 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.
  626. .. rst-class:: classref-item-separator
  627. ----
  628. .. _class_@GDScript_method_get_stack:
  629. .. rst-class:: classref-method
  630. :ref:`Array<class_Array>` **get_stack**\ (\ ) :ref:`🔗<class_@GDScript_method_get_stack>`
  631. Returns an array of dictionaries representing the current call stack.
  632. ::
  633. func _ready():
  634. foo()
  635. func foo():
  636. bar()
  637. func bar():
  638. print(get_stack())
  639. Starting from ``_ready()``, ``bar()`` would print:
  640. .. code:: text
  641. [{function:bar, line:12, source:res://script.gd}, {function:foo, line:9, source:res://script.gd}, {function:_ready, line:6, source:res://script.gd}]
  642. See also :ref:`print_debug()<class_@GDScript_method_print_debug>`, :ref:`print_stack()<class_@GDScript_method_print_stack>`, and :ref:`Engine.capture_script_backtraces()<class_Engine_method_capture_script_backtraces>`.
  643. \ **Note:** By default, backtraces are only available in editor builds and debug builds. To enable them for release builds as well, you need to enable :ref:`ProjectSettings.debug/settings/gdscript/always_track_call_stacks<class_ProjectSettings_property_debug/settings/gdscript/always_track_call_stacks>`.
  644. .. rst-class:: classref-item-separator
  645. ----
  646. .. _class_@GDScript_method_inst_to_dict:
  647. .. rst-class:: classref-method
  648. :ref:`Dictionary<class_Dictionary>` **inst_to_dict**\ (\ instance\: :ref:`Object<class_Object>`\ ) :ref:`🔗<class_@GDScript_method_inst_to_dict>`
  649. **Deprecated:** Consider using :ref:`JSON.from_native()<class_JSON_method_from_native>` or :ref:`Object.get_property_list()<class_Object_method_get_property_list>` instead.
  650. Returns the passed ``instance`` converted to a :ref:`Dictionary<class_Dictionary>`. Can be useful for serializing.
  651. ::
  652. var foo = "bar"
  653. func _ready():
  654. var d = inst_to_dict(self)
  655. print(d.keys())
  656. print(d.values())
  657. Prints out:
  658. .. code:: text
  659. [@subpath, @path, foo]
  660. [, res://test.gd, bar]
  661. \ **Note:** This function can only be used to serialize objects with an attached :ref:`GDScript<class_GDScript>` stored in a separate file. Objects without an attached script, with a script written in another language, or with a built-in script are not supported.
  662. \ **Note:** This function is not recursive, which means that nested objects will not be represented as dictionaries. Also, properties passed by reference (:ref:`Object<class_Object>`, :ref:`Dictionary<class_Dictionary>`, :ref:`Array<class_Array>`, and packed arrays) are copied by reference, not duplicated.
  663. .. rst-class:: classref-item-separator
  664. ----
  665. .. _class_@GDScript_method_is_instance_of:
  666. .. rst-class:: classref-method
  667. :ref:`bool<class_bool>` **is_instance_of**\ (\ value\: :ref:`Variant<class_Variant>`, type\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_@GDScript_method_is_instance_of>`
  668. Returns ``true`` if ``value`` is an instance of ``type``. The ``type`` value must be one of the following:
  669. - A constant from the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` enumeration, for example :ref:`@GlobalScope.TYPE_INT<class_@GlobalScope_constant_TYPE_INT>`.
  670. - An :ref:`Object<class_Object>`-derived class which exists in :ref:`ClassDB<class_ClassDB>`, for example :ref:`Node<class_Node>`.
  671. - A :ref:`Script<class_Script>` (you can use any class, including inner one).
  672. 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 to check the type dynamically.
  673. \ **Examples:**\
  674. ::
  675. print(is_instance_of(a, TYPE_INT))
  676. print(is_instance_of(a, Node))
  677. print(is_instance_of(a, MyClass))
  678. print(is_instance_of(a, MyClass.InnerClass))
  679. \ **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.
  680. 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).
  681. .. rst-class:: classref-item-separator
  682. ----
  683. .. _class_@GDScript_method_len:
  684. .. rst-class:: classref-method
  685. :ref:`int<class_int>` **len**\ (\ var\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_@GDScript_method_len>`
  686. Returns the length of the given Variant ``var``. The length can be the character count of a :ref:`String<class_String>` or :ref:`StringName<class_StringName>`, 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.
  687. ::
  688. var a = [1, 2, 3, 4]
  689. len(a) # Returns 4
  690. var b = "Hello!"
  691. len(b) # Returns 6
  692. .. rst-class:: classref-item-separator
  693. ----
  694. .. _class_@GDScript_method_load:
  695. .. rst-class:: classref-method
  696. :ref:`Resource<class_Resource>` **load**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_method_load>`
  697. 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>`. This method is equivalent of using :ref:`ResourceLoader.load()<class_ResourceLoader_method_load>` with :ref:`ResourceLoader.CACHE_MODE_REUSE<class_ResourceLoader_constant_CACHE_MODE_REUSE>`.
  698. \ **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.
  699. ::
  700. # Load a scene called "main" located in the root of the project directory and cache it in a variable.
  701. var main = load("res://main.tscn") # main will contain a PackedScene resource.
  702. \ **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.
  703. This function is a simplified version of :ref:`ResourceLoader.load()<class_ResourceLoader_method_load>`, which can be used for more advanced scenarios.
  704. \ **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>`.
  705. \ **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``.
  706. .. rst-class:: classref-item-separator
  707. ----
  708. .. _class_@GDScript_method_ord:
  709. .. rst-class:: classref-method
  710. :ref:`int<class_int>` **ord**\ (\ char\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_method_ord>`
  711. Returns an integer representing the Unicode code point of the given character ``char``, which should be a string of length 1.
  712. ::
  713. print(ord("A")) # Prints 65
  714. print(ord("🤖")) # Prints 129302
  715. This is the inverse of :ref:`char()<class_@GDScript_method_char>`. See also :ref:`String.chr()<class_String_method_chr>` and :ref:`String.unicode_at()<class_String_method_unicode_at>`.
  716. .. rst-class:: classref-item-separator
  717. ----
  718. .. _class_@GDScript_method_preload:
  719. .. rst-class:: classref-method
  720. :ref:`Resource<class_Resource>` **preload**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_method_preload>`
  721. 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>`.
  722. \ **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.
  723. ::
  724. # Create instance of a scene.
  725. var diamond = preload("res://diamond.tscn").instantiate()
  726. \ **Note:** :ref:`preload()<class_@GDScript_method_preload>` is a keyword, not a function. So you cannot access it as a :ref:`Callable<class_Callable>`.
  727. .. rst-class:: classref-item-separator
  728. ----
  729. .. _class_@GDScript_method_print_debug:
  730. .. rst-class:: classref-method
  731. |void| **print_debug**\ (\ ...\ ) |vararg| :ref:`🔗<class_@GDScript_method_print_debug>`
  732. Like :ref:`@GlobalScope.print()<class_@GlobalScope_method_print>`, but includes the current stack frame when running with the debugger turned on.
  733. The output in the console may look like the following:
  734. .. code:: text
  735. Test print
  736. At: res://test.gd:15:_process()
  737. See also :ref:`print_stack()<class_@GDScript_method_print_stack>`, :ref:`get_stack()<class_@GDScript_method_get_stack>`, and :ref:`Engine.capture_script_backtraces()<class_Engine_method_capture_script_backtraces>`.
  738. \ **Note:** By default, backtraces are only available in editor builds and debug builds. To enable them for release builds as well, you need to enable :ref:`ProjectSettings.debug/settings/gdscript/always_track_call_stacks<class_ProjectSettings_property_debug/settings/gdscript/always_track_call_stacks>`.
  739. .. rst-class:: classref-item-separator
  740. ----
  741. .. _class_@GDScript_method_print_stack:
  742. .. rst-class:: classref-method
  743. |void| **print_stack**\ (\ ) :ref:`🔗<class_@GDScript_method_print_stack>`
  744. Prints a stack trace at the current code location.
  745. The output in the console may look like the following:
  746. .. code:: text
  747. Frame 0 - res://test.gd:16 in function '_process'
  748. See also :ref:`print_debug()<class_@GDScript_method_print_debug>`, :ref:`get_stack()<class_@GDScript_method_get_stack>`, and :ref:`Engine.capture_script_backtraces()<class_Engine_method_capture_script_backtraces>`.
  749. \ **Note:** By default, backtraces are only available in editor builds and debug builds. To enable them for release builds as well, you need to enable :ref:`ProjectSettings.debug/settings/gdscript/always_track_call_stacks<class_ProjectSettings_property_debug/settings/gdscript/always_track_call_stacks>`.
  750. .. rst-class:: classref-item-separator
  751. ----
  752. .. _class_@GDScript_method_range:
  753. .. rst-class:: classref-method
  754. :ref:`Array<class_Array>` **range**\ (\ ...\ ) |vararg| :ref:`🔗<class_@GDScript_method_range>`
  755. Returns an array with the given range. :ref:`range()<class_@GDScript_method_range>` can be called in three ways:
  756. \ ``range(n: int)``: Starts from 0, increases by steps of 1, and stops *before* ``n``. The argument ``n`` is **exclusive**.
  757. \ ``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.
  758. \ ``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.
  759. \ :ref:`range()<class_@GDScript_method_range>` converts all arguments to :ref:`int<class_int>` before processing.
  760. \ **Note:** Returns an empty array if no value meets the value constraint (e.g. ``range(2, 5, -1)`` or ``range(5, 5, 1)``).
  761. \ **Examples:**\
  762. ::
  763. print(range(4)) # Prints [0, 1, 2, 3]
  764. print(range(2, 5)) # Prints [2, 3, 4]
  765. print(range(0, 6, 2)) # Prints [0, 2, 4]
  766. print(range(4, 1, -1)) # Prints [4, 3, 2]
  767. To iterate over an :ref:`Array<class_Array>` backwards, use:
  768. ::
  769. var array = [3, 6, 9]
  770. for i in range(array.size() - 1, -1, -1):
  771. print(array[i])
  772. Output:
  773. .. code:: text
  774. 9
  775. 6
  776. 3
  777. To iterate over :ref:`float<class_float>`, convert them in the loop.
  778. ::
  779. for i in range (3, 0, -1):
  780. print(i / 10.0)
  781. Output:
  782. .. code:: text
  783. 0.3
  784. 0.2
  785. 0.1
  786. .. rst-class:: classref-item-separator
  787. ----
  788. .. _class_@GDScript_method_type_exists:
  789. .. rst-class:: classref-method
  790. :ref:`bool<class_bool>` **type_exists**\ (\ type\: :ref:`StringName<class_StringName>`\ ) :ref:`🔗<class_@GDScript_method_type_exists>`
  791. 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>`.
  792. ::
  793. type_exists("Sprite2D") # Returns true
  794. type_exists("NonExistentClass") # Returns false
  795. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  796. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  797. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  798. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  799. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  800. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  801. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  802. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  803. .. |void| replace:: :abbr:`void (No return value.)`