[email protected] 68 KB

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