@GDScript.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="@GDScript" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
  3. <brief_description>
  4. Built-in GDScript functions.
  5. </brief_description>
  6. <description>
  7. A list of GDScript-specific utility functions and annotations accessible from any script.
  8. For the list of the global functions and constants see [@GlobalScope].
  9. </description>
  10. <tutorials>
  11. <link title="GDScript exports">$DOCS_URL/tutorials/scripting/gdscript/gdscript_exports.html</link>
  12. </tutorials>
  13. <methods>
  14. <method name="Color8">
  15. <return type="Color" />
  16. <param index="0" name="r8" type="int" />
  17. <param index="1" name="g8" type="int" />
  18. <param index="2" name="b8" type="int" />
  19. <param index="3" name="a8" type="int" default="255" />
  20. <description>
  21. Returns a [Color] constructed from red ([param r8]), green ([param g8]), blue ([param b8]), and optionally alpha ([param a8]) integer channels, each divided by [code]255.0[/code] for their final value.
  22. [codeblock]
  23. var red = Color8(255, 0, 0) # Same as Color(1, 0, 0).
  24. var dark_blue = Color8(0, 0, 51) # Same as Color(0, 0, 0.2).
  25. var my_color = Color8(306, 255, 0, 102) # Same as Color(1.2, 1, 0, 0.4).
  26. [/codeblock]
  27. </description>
  28. </method>
  29. <method name="assert">
  30. <return type="void" />
  31. <param index="0" name="condition" type="bool" />
  32. <param index="1" name="message" type="String" default="&quot;&quot;" />
  33. <description>
  34. Asserts that the [param condition] is [code]true[/code]. If the [param condition] is [code]false[/code], 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 [method @GlobalScope.push_error] for reporting errors to project developers or add-on users.
  35. An optional [param 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.
  36. [b]Warning:[/b] For performance reasons, the code inside [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 [method assert] call. Otherwise, the project will behave differently when exported in release mode.
  37. [codeblock]
  38. # Imagine we always want speed to be between 0 and 20.
  39. var speed = -10
  40. assert(speed &lt; 20) # True, the program will continue.
  41. assert(speed &gt;= 0) # False, the program will stop.
  42. assert(speed &gt;= 0 and speed &lt; 20) # You can also combine the two conditional statements in one check.
  43. assert(speed &lt; 20, "the speed limit is 20") # Show a message.
  44. [/codeblock]
  45. </description>
  46. </method>
  47. <method name="char">
  48. <return type="String" />
  49. <param index="0" name="char" type="int" />
  50. <description>
  51. Returns a single character (as a [String]) of the given Unicode code point (which is compatible with ASCII code).
  52. [codeblock]
  53. a = char(65) # a is "A"
  54. a = char(65 + 32) # a is "a"
  55. a = char(8364) # a is "€"
  56. [/codeblock]
  57. </description>
  58. </method>
  59. <method name="convert">
  60. <return type="Variant" />
  61. <param index="0" name="what" type="Variant" />
  62. <param index="1" name="type" type="int" />
  63. <description>
  64. Converts [param what] to [param type] in the best way possible. The [param type] uses the [enum Variant.Type] values.
  65. [codeblock]
  66. var a = [4, 2.5, 1.2]
  67. print(a is Array) # Prints true
  68. var b = convert(a, TYPE_PACKED_BYTE_ARRAY)
  69. print(b) # Prints [4, 2, 1]
  70. print(b is Array) # Prints false
  71. [/codeblock]
  72. </description>
  73. </method>
  74. <method name="dict_to_inst">
  75. <return type="Object" />
  76. <param index="0" name="dictionary" type="Dictionary" />
  77. <description>
  78. Converts a [param dictionary] (created with [method inst_to_dict]) back to an Object instance. Can be useful for deserializing.
  79. </description>
  80. </method>
  81. <method name="get_stack">
  82. <return type="Array" />
  83. <description>
  84. Returns an array of dictionaries representing the current call stack. See also [method print_stack].
  85. [codeblock]
  86. func _ready():
  87. foo()
  88. func foo():
  89. bar()
  90. func bar():
  91. print(get_stack())
  92. [/codeblock]
  93. Starting from [code]_ready()[/code], [code]bar()[/code] would print:
  94. [codeblock]
  95. [{function:bar, line:12, source:res://script.gd}, {function:foo, line:9, source:res://script.gd}, {function:_ready, line:6, source:res://script.gd}]
  96. [/codeblock]
  97. [b]Note:[/b] This function only works if the running instance is connected to a debugging server (i.e. an editor instance). [method get_stack] will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
  98. [b]Note:[/b] Calling this function from a [Thread] is not supported. Doing so will return an empty array.
  99. </description>
  100. </method>
  101. <method name="inst_to_dict">
  102. <return type="Dictionary" />
  103. <param index="0" name="instance" type="Object" />
  104. <description>
  105. Returns the passed [param instance] converted to a Dictionary. Can be useful for serializing.
  106. [b]Note:[/b] Cannot be used to serialize objects with built-in scripts attached or objects allocated within built-in scripts.
  107. [codeblock]
  108. var foo = "bar"
  109. func _ready():
  110. var d = inst_to_dict(self)
  111. print(d.keys())
  112. print(d.values())
  113. [/codeblock]
  114. Prints out:
  115. [codeblock]
  116. [@subpath, @path, foo]
  117. [, res://test.gd, bar]
  118. [/codeblock]
  119. </description>
  120. </method>
  121. <method name="is_instance_of">
  122. <return type="bool" />
  123. <param index="0" name="value" type="Variant" />
  124. <param index="1" name="type" type="Variant" />
  125. <description>
  126. Returns [code]true[/code] if [param value] is an instance of [param type]. The [param type] value must be one of the following:
  127. - A constant from the [enum Variant.Type] enumeration, for example [constant TYPE_INT].
  128. - An [Object]-derived class which exists in [ClassDB], for example [Node].
  129. - A [Script] (you can use any class, including inner one).
  130. Unlike the right operand of the [code]is[/code] operator, [param type] can be a non-constant value. The [code]is[/code] operator supports more features (such as typed arrays) and is more performant. Use the operator instead of this method if you do not need dynamic type checking.
  131. Examples:
  132. [codeblock]
  133. print(is_instance_of(a, TYPE_INT))
  134. print(is_instance_of(a, Node))
  135. print(is_instance_of(a, MyClass))
  136. print(is_instance_of(a, MyClass.InnerClass))
  137. [/codeblock]
  138. [b]Note:[/b] If [param value] and/or [param type] are freed objects (see [method @GlobalScope.is_instance_valid]), or [param type] is not one of the above options, this method will raise an runtime error.
  139. See also [method @GlobalScope.typeof], [method type_exists], [method Array.is_same_typed] (and other [Array] methods).
  140. </description>
  141. </method>
  142. <method name="len">
  143. <return type="int" />
  144. <param index="0" name="var" type="Variant" />
  145. <description>
  146. Returns the length of the given Variant [param var]. The length can be the character count of a [String], the element count of any array type or the size of a [Dictionary]. For every other Variant type, a run-time error is generated and execution is stopped.
  147. [codeblock]
  148. a = [1, 2, 3, 4]
  149. len(a) # Returns 4
  150. b = "Hello!"
  151. len(b) # Returns 6
  152. [/codeblock]
  153. </description>
  154. </method>
  155. <method name="load">
  156. <return type="Resource" />
  157. <param index="0" name="path" type="String" />
  158. <description>
  159. Returns a [Resource] from the filesystem located at the absolute [param 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 [method preload].
  160. [b]Note:[/b] 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.
  161. [codeblock]
  162. # Load a scene called "main" located in the root of the project directory and cache it in a variable.
  163. var main = load("res://main.tscn") # main will contain a PackedScene resource.
  164. [/codeblock]
  165. [b]Important:[/b] The path must be absolute. A relative path will always return [code]null[/code].
  166. This function is a simplified version of [method ResourceLoader.load], which can be used for more advanced scenarios.
  167. [b]Note:[/b] Files have to be imported into the engine first to load them using this function. If you want to load [Image]s at run-time, you may use [method Image.load]. If you want to import audio files, you can use the snippet described in [member AudioStreamMP3.data].
  168. </description>
  169. </method>
  170. <method name="preload">
  171. <return type="Resource" />
  172. <param index="0" name="path" type="String" />
  173. <description>
  174. Returns a [Resource] from the filesystem located at [param 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 [param path] to be a constant [String]. If you want to load a resource from a dynamic/variable path, use [method load].
  175. [b]Note:[/b] 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.
  176. [codeblock]
  177. # Create instance of a scene.
  178. var diamond = preload("res://diamond.tscn").instantiate()
  179. [/codeblock]
  180. </description>
  181. </method>
  182. <method name="print_debug" qualifiers="vararg">
  183. <return type="void" />
  184. <description>
  185. Like [method @GlobalScope.print], but includes the current stack frame when running with the debugger turned on.
  186. The output in the console may look like the following:
  187. [codeblock]
  188. Test print
  189. At: res://test.gd:15:_process()
  190. [/codeblock]
  191. [b]Note:[/b] Calling this function from a [Thread] is not supported. Doing so will instead print the thread ID.
  192. </description>
  193. </method>
  194. <method name="print_stack">
  195. <return type="void" />
  196. <description>
  197. Prints a stack trace at the current code location. See also [method get_stack].
  198. The output in the console may look like the following:
  199. [codeblock]
  200. Frame 0 - res://test.gd:16 in function '_process'
  201. [/codeblock]
  202. [b]Note:[/b] This function only works if the running instance is connected to a debugging server (i.e. an editor instance). [method print_stack] will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
  203. [b]Note:[/b] Calling this function from a [Thread] is not supported. Doing so will instead print the thread ID.
  204. </description>
  205. </method>
  206. <method name="range" qualifiers="vararg">
  207. <return type="Array" />
  208. <description>
  209. Returns an array with the given range. [method range] can be called in three ways:
  210. [code]range(n: int)[/code]: Starts from 0, increases by steps of 1, and stops [i]before[/i] [code]n[/code]. The argument [code]n[/code] is [b]exclusive[/b].
  211. [code]range(b: int, n: int)[/code]: Starts from [code]b[/code], increases by steps of 1, and stops [i]before[/i] [code]n[/code]. The arguments [code]b[/code] and [code]n[/code] are [b]inclusive[/b] and [b]exclusive[/b], respectively.
  212. [code]range(b: int, n: int, s: int)[/code]: Starts from [code]b[/code], increases/decreases by steps of [code]s[/code], and stops [i]before[/i] [code]n[/code]. The arguments [code]b[/code] and [code]n[/code] are [b]inclusive[/b] and [b]exclusive[/b], respectively. The argument [code]s[/code] [b]can[/b] be negative, but not [code]0[/code]. If [code]s[/code] is [code]0[/code], an error message is printed.
  213. [method range] converts all arguments to [int] before processing.
  214. [b]Note:[/b] Returns an empty array if no value meets the value constraint (e.g. [code]range(2, 5, -1)[/code] or [code]range(5, 5, 1)[/code]).
  215. Examples:
  216. [codeblock]
  217. print(range(4)) # Prints [0, 1, 2, 3]
  218. print(range(2, 5)) # Prints [2, 3, 4]
  219. print(range(0, 6, 2)) # Prints [0, 2, 4]
  220. print(range(4, 1, -1)) # Prints [4, 3, 2]
  221. [/codeblock]
  222. To iterate over an [Array] backwards, use:
  223. [codeblock]
  224. var array = [3, 6, 9]
  225. for i in range(array.size(), 0, -1):
  226. print(array[i - 1])
  227. [/codeblock]
  228. Output:
  229. [codeblock]
  230. 9
  231. 6
  232. 3
  233. [/codeblock]
  234. To iterate over [float], convert them in the loop.
  235. [codeblock]
  236. for i in range (3, 0, -1):
  237. print(i / 10.0)
  238. [/codeblock]
  239. Output:
  240. [codeblock]
  241. 0.3
  242. 0.2
  243. 0.1
  244. [/codeblock]
  245. </description>
  246. </method>
  247. <method name="type_exists">
  248. <return type="bool" />
  249. <param index="0" name="type" type="StringName" />
  250. <description>
  251. Returns [code]true[/code] if the given [Object]-derived class exists in [ClassDB]. Note that [Variant] data types are not registered in [ClassDB].
  252. [codeblock]
  253. type_exists("Sprite2D") # Returns true
  254. type_exists("NonExistentClass") # Returns false
  255. [/codeblock]
  256. </description>
  257. </method>
  258. </methods>
  259. <constants>
  260. <constant name="PI" value="3.14159265358979">
  261. Constant that represents how many times the diameter of a circle fits around its perimeter. This is equivalent to [code]TAU / 2[/code], or 180 degrees in rotations.
  262. </constant>
  263. <constant name="TAU" value="6.28318530717959">
  264. The circle constant, the circumference of the unit circle in radians. This is equivalent to [code]PI * 2[/code], or 360 degrees in rotations.
  265. </constant>
  266. <constant name="INF" value="inf">
  267. Positive floating-point infinity. This is the result of floating-point division when the divisor is [code]0.0[/code]. For negative infinity, use [code]-INF[/code]. Dividing by [code]-0.0[/code] will result in negative infinity if the numerator is positive, so dividing by [code]0.0[/code] is not the same as dividing by [code]-0.0[/code] (despite [code]0.0 == -0.0[/code] returning [code]true[/code]).
  268. [b]Warning:[/b] Numeric infinity is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer number by [code]0[/code] will not result in [constant INF] and will result in a run-time error instead.
  269. </constant>
  270. <constant name="NAN" value="nan">
  271. "Not a Number", an invalid floating-point value. [constant NAN] has special properties, including that it is not equal to itself ([code]NAN == NAN[/code] returns [code]false[/code]). It is output by some invalid operations, such as dividing floating-point [code]0.0[/code] by [code]0.0[/code].
  272. [b]Warning:[/b] "Not a Number" is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer [code]0[/code] by [code]0[/code] will not result in [constant NAN] and will result in a run-time error instead.
  273. </constant>
  274. </constants>
  275. <annotations>
  276. <annotation name="@export">
  277. <return type="void" />
  278. <description>
  279. 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.
  280. [codeblock]
  281. @export var string = ""
  282. @export var int_number = 5
  283. @export var float_number: float = 5
  284. @export var image : Image
  285. [/codeblock]
  286. </description>
  287. </annotation>
  288. <annotation name="@export_category">
  289. <return type="void" />
  290. <param index="0" name="name" type="String" />
  291. <description>
  292. Define a new category for the following exported properties. This helps to organize properties in the Inspector dock.
  293. See also [constant PROPERTY_USAGE_CATEGORY].
  294. [codeblock]
  295. @export_category("Statistics")
  296. @export var hp = 30
  297. @export var speed = 1.25
  298. [/codeblock]
  299. [b]Note:[/b] 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 [annotation @export_group] and [annotation @export_subgroup], instead.
  300. </description>
  301. </annotation>
  302. <annotation name="@export_color_no_alpha">
  303. <return type="void" />
  304. <description>
  305. Export a [Color] property without allowing its transparency ([member Color.a]) to be edited.
  306. See also [constant PROPERTY_HINT_COLOR_NO_ALPHA].
  307. [codeblock]
  308. @export_color_no_alpha var dye_color : Color
  309. [/codeblock]
  310. </description>
  311. </annotation>
  312. <annotation name="@export_dir">
  313. <return type="void" />
  314. <description>
  315. Export a [String] property as a path to a directory. The path will be limited to the project folder and its subfolders. See [annotation @export_global_dir] to allow picking from the entire filesystem.
  316. See also [constant PROPERTY_HINT_DIR].
  317. [codeblock]
  318. @export_dir var sprite_folder_path: String
  319. [/codeblock]
  320. </description>
  321. </annotation>
  322. <annotation name="@export_enum" qualifiers="vararg">
  323. <return type="void" />
  324. <param index="0" name="names" type="String" />
  325. <description>
  326. Export an [int] or [String] property as an enumerated list of options. If the property is an [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 [String], then the value is stored.
  327. See also [constant PROPERTY_HINT_ENUM].
  328. [codeblock]
  329. @export_enum("Warrior", "Magician", "Thief") var character_class: int
  330. @export_enum("Slow:30", "Average:60", "Very Fast:200") var character_speed: int
  331. @export_enum("Rebecca", "Mary", "Leah") var character_name: String
  332. [/codeblock]
  333. If you want to set an initial value, you must specify it explicitly:
  334. [codeblock]
  335. @export_enum("Rebecca", "Mary", "Leah") var character_name: String = "Rebecca"
  336. [/codeblock]
  337. If you want to use named GDScript enums, then use [annotation @export] instead:
  338. [codeblock]
  339. enum CharacterName {REBECCA, MARY, LEAH}
  340. @export var character_name: CharacterName
  341. [/codeblock]
  342. </description>
  343. </annotation>
  344. <annotation name="@export_exp_easing" qualifiers="vararg">
  345. <return type="void" />
  346. <param index="0" name="hints" type="String" default="&quot;&quot;" />
  347. <description>
  348. Export a floating-point property with an easing editor widget. Additional hints can be provided to adjust the behavior of the widget. [code]"attenuation"[/code] flips the curve, which makes it more intuitive for editing attenuation properties. [code]"positive_only"[/code] limits values to only be greater than or equal to zero.
  349. See also [constant PROPERTY_HINT_EXP_EASING].
  350. [codeblock]
  351. @export_exp_easing var transition_speed
  352. @export_exp_easing("attenuation") var fading_attenuation
  353. @export_exp_easing("positive_only") var effect_power
  354. [/codeblock]
  355. </description>
  356. </annotation>
  357. <annotation name="@export_file" qualifiers="vararg">
  358. <return type="void" />
  359. <param index="0" name="filter" type="String" default="&quot;&quot;" />
  360. <description>
  361. Export a [String] property as a path to a file. The path will be limited to the project folder and its subfolders. See [annotation @export_global_file] to allow picking from the entire filesystem.
  362. If [param filter] is provided, only matching files will be available for picking.
  363. See also [constant PROPERTY_HINT_FILE].
  364. [codeblock]
  365. @export_file var sound_effect_path: String
  366. @export_file("*.txt") var notes_path: String
  367. [/codeblock]
  368. </description>
  369. </annotation>
  370. <annotation name="@export_flags" qualifiers="vararg">
  371. <return type="void" />
  372. <param index="0" name="names" type="String" />
  373. <description>
  374. Export an integer property as a bit flag field. This allows to store several "checked" or [code]true[/code] values with one property, and comfortably select them from the Inspector dock.
  375. See also [constant PROPERTY_HINT_FLAGS].
  376. [codeblock]
  377. @export_flags("Fire", "Water", "Earth", "Wind") var spell_elements = 0
  378. [/codeblock]
  379. You can add explicit values using a colon:
  380. [codeblock]
  381. @export_flags("Self:4", "Allies:8", "Foes:16") var spell_targets = 0
  382. [/codeblock]
  383. You can also combine several flags:
  384. [codeblock]
  385. @export_flags("Self:4", "Allies:8", "Self and Allies:12", "Foes:16")
  386. var spell_targets = 0
  387. [/codeblock]
  388. [b]Note:[/b] A flag value must be at least [code]1[/code] and at most [code]2 ** 32 - 1[/code].
  389. [b]Note:[/b] Unlike [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.
  390. [codeblock]
  391. @export_flags("A:16", "B", "C") var x
  392. [/codeblock]
  393. </description>
  394. </annotation>
  395. <annotation name="@export_flags_2d_navigation">
  396. <return type="void" />
  397. <description>
  398. 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 [member ProjectSettings.layer_names/2d_navigation/layer_1].
  399. See also [constant PROPERTY_HINT_LAYERS_2D_NAVIGATION].
  400. [codeblock]
  401. @export_flags_2d_navigation var navigation_layers: int
  402. [/codeblock]
  403. </description>
  404. </annotation>
  405. <annotation name="@export_flags_2d_physics">
  406. <return type="void" />
  407. <description>
  408. 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 [member ProjectSettings.layer_names/2d_physics/layer_1].
  409. See also [constant PROPERTY_HINT_LAYERS_2D_PHYSICS].
  410. [codeblock]
  411. @export_flags_2d_physics var physics_layers: int
  412. [/codeblock]
  413. </description>
  414. </annotation>
  415. <annotation name="@export_flags_2d_render">
  416. <return type="void" />
  417. <description>
  418. 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 [member ProjectSettings.layer_names/2d_render/layer_1].
  419. See also [constant PROPERTY_HINT_LAYERS_2D_RENDER].
  420. [codeblock]
  421. @export_flags_2d_render var render_layers: int
  422. [/codeblock]
  423. </description>
  424. </annotation>
  425. <annotation name="@export_flags_3d_navigation">
  426. <return type="void" />
  427. <description>
  428. 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 [member ProjectSettings.layer_names/3d_navigation/layer_1].
  429. See also [constant PROPERTY_HINT_LAYERS_3D_NAVIGATION].
  430. [codeblock]
  431. @export_flags_3d_navigation var navigation_layers: int
  432. [/codeblock]
  433. </description>
  434. </annotation>
  435. <annotation name="@export_flags_3d_physics">
  436. <return type="void" />
  437. <description>
  438. 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 [member ProjectSettings.layer_names/3d_physics/layer_1].
  439. See also [constant PROPERTY_HINT_LAYERS_3D_PHYSICS].
  440. [codeblock]
  441. @export_flags_3d_physics var physics_layers: int
  442. [/codeblock]
  443. </description>
  444. </annotation>
  445. <annotation name="@export_flags_3d_render">
  446. <return type="void" />
  447. <description>
  448. 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 [member ProjectSettings.layer_names/3d_render/layer_1].
  449. See also [constant PROPERTY_HINT_LAYERS_3D_RENDER].
  450. [codeblock]
  451. @export_flags_3d_render var render_layers: int
  452. [/codeblock]
  453. </description>
  454. </annotation>
  455. <annotation name="@export_global_dir">
  456. <return type="void" />
  457. <description>
  458. Export a [String] property as an absolute path to a directory. The path can be picked from the entire filesystem. See [annotation @export_dir] to limit it to the project folder and its subfolders.
  459. See also [constant PROPERTY_HINT_GLOBAL_DIR].
  460. [codeblock]
  461. @export_global_dir var sprite_folder_path: String
  462. [/codeblock]
  463. </description>
  464. </annotation>
  465. <annotation name="@export_global_file" qualifiers="vararg">
  466. <return type="void" />
  467. <param index="0" name="filter" type="String" default="&quot;&quot;" />
  468. <description>
  469. Export a [String] property as an absolute path to a file. The path can be picked from the entire filesystem. See [annotation @export_file] to limit it to the project folder and its subfolders.
  470. If [param filter] is provided, only matching files will be available for picking.
  471. See also [constant PROPERTY_HINT_GLOBAL_FILE].
  472. [codeblock]
  473. @export_global_file var sound_effect_path: String
  474. @export_global_file("*.txt") var notes_path: String
  475. [/codeblock]
  476. </description>
  477. </annotation>
  478. <annotation name="@export_group">
  479. <return type="void" />
  480. <param index="0" name="name" type="String" />
  481. <param index="1" name="prefix" type="String" default="&quot;&quot;" />
  482. <description>
  483. 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 [param 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.
  484. If no [param prefix] is provided, the every following property is 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, [code]@export_group("", "")[/code].
  485. Groups cannot be nested, use [annotation @export_subgroup] to add subgroups within groups.
  486. See also [constant PROPERTY_USAGE_GROUP].
  487. [codeblock]
  488. @export_group("Racer Properties")
  489. @export var nickname = "Nick"
  490. @export var age = 26
  491. @export_group("Car Properties", "car_")
  492. @export var car_label = "Speedy"
  493. @export var car_number = 3
  494. @export_group("", "")
  495. @export var ungrouped_number = 3
  496. [/codeblock]
  497. </description>
  498. </annotation>
  499. <annotation name="@export_multiline">
  500. <return type="void" />
  501. <description>
  502. Export a [String] property with a large [TextEdit] widget instead of a [LineEdit]. This adds support for multiline content and makes it easier to edit large amount of text stored in the property.
  503. See also [constant PROPERTY_HINT_MULTILINE_TEXT].
  504. [codeblock]
  505. @export_multiline var character_biography
  506. [/codeblock]
  507. </description>
  508. </annotation>
  509. <annotation name="@export_node_path" qualifiers="vararg">
  510. <return type="void" />
  511. <param index="0" name="type" type="String" default="&quot;&quot;" />
  512. <description>
  513. Export a [NodePath] property with a filter for allowed node types.
  514. See also [constant PROPERTY_HINT_NODE_PATH_VALID_TYPES].
  515. [codeblock]
  516. @export_node_path("Button", "TouchScreenButton") var some_button
  517. [/codeblock]
  518. </description>
  519. </annotation>
  520. <annotation name="@export_placeholder">
  521. <return type="void" />
  522. <param index="0" name="placeholder" type="String" />
  523. <description>
  524. Export a [String] property with a placeholder text displayed in the editor widget when no value is present.
  525. See also [constant PROPERTY_HINT_PLACEHOLDER_TEXT].
  526. [codeblock]
  527. @export_placeholder("Name in lowercase") var character_id: String
  528. [/codeblock]
  529. </description>
  530. </annotation>
  531. <annotation name="@export_range" qualifiers="vararg">
  532. <return type="void" />
  533. <param index="0" name="min" type="float" />
  534. <param index="1" name="max" type="float" />
  535. <param index="2" name="step" type="float" default="1.0" />
  536. <param index="3" name="extra_hints" type="String" default="&quot;&quot;" />
  537. <description>
  538. Export an [int] or [float] property as a range value. The range must be defined by [param min] and [param max], as well as an optional [param step] and a variety of extra hints. The [param step] defaults to [code]1[/code] for integer properties. For floating-point numbers this value depends on your [code]EditorSettings.interface/inspector/default_float_step[/code] setting.
  539. If hints [code]"or_greater"[/code] and [code]"or_less"[/code] are provided, the editor widget will not cap the value at range boundaries. The [code]"exp"[/code] hint will make the edited values on range to change exponentially. The [code]"hide_slider"[/code] hint will hide the slider element of the editor widget.
  540. Hints also allow to indicate the units for the edited value. Using [code]"radians"[/code] you can specify that the actual value is in radians, but should be displayed in degrees in the Inspector dock. [code]"degrees"[/code] allows to add a degree sign as a unit suffix. Finally, a custom suffix can be provided using [code]"suffix:unit"[/code], where "unit" can be any string.
  541. See also [constant PROPERTY_HINT_RANGE].
  542. [codeblock]
  543. @export_range(0, 20) var number
  544. @export_range(-10, 20) var number
  545. @export_range(-10, 20, 0.2) var number: float
  546. @export_range(0, 100, 1, "or_greater") var power_percent
  547. @export_range(0, 100, 1, "or_greater", "or_less") var health_delta
  548. @export_range(-3.14, 3.14, 0.001, "radians") var angle_radians
  549. @export_range(0, 360, 1, "degrees") var angle_degrees
  550. @export_range(-8, 8, 2, "suffix:px") var target_offset
  551. [/codeblock]
  552. </description>
  553. </annotation>
  554. <annotation name="@export_subgroup">
  555. <return type="void" />
  556. <param index="0" name="name" type="String" />
  557. <param index="1" name="prefix" type="String" default="&quot;&quot;" />
  558. <description>
  559. 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 [annotation @export_group].
  560. See also [constant PROPERTY_USAGE_SUBGROUP].
  561. [codeblock]
  562. @export_group("Racer Properties")
  563. @export var nickname = "Nick"
  564. @export var age = 26
  565. @export_subgroup("Car Properties", "car_")
  566. @export var car_label = "Speedy"
  567. @export var car_number = 3
  568. [/codeblock]
  569. [b]Note:[/b] Subgroups cannot be nested, they only provide one extra level of depth. Just like the next group ends the previous group, so do the subsequent subgroups.
  570. </description>
  571. </annotation>
  572. <annotation name="@icon">
  573. <return type="void" />
  574. <param index="0" name="icon_path" type="String" />
  575. <description>
  576. Add a custom icon to the current script. The script must be registered as a global class using the [code]class_name[/code] keyword for this to have a visible effect. The icon specified at [param icon_path] is displayed in the Scene dock for every node of that class, as well as in various editor dialogs.
  577. [codeblock]
  578. @icon("res://path/to/class/icon.svg")
  579. [/codeblock]
  580. [b]Note:[/b] Only the script can have a custom icon. Inner classes are not supported.
  581. [b]Note:[/b] As annotations describe their subject, the [code]@icon[/code] annotation must be placed before the class definition and inheritance.
  582. [b]Note:[/b] Unlike other annotations, the argument of the [code]@icon[/code] annotation must be a string literal (constant expressions are not supported).
  583. </description>
  584. </annotation>
  585. <annotation name="@onready">
  586. <return type="void" />
  587. <description>
  588. Mark the following property as assigned when the [Node] is ready. Values for these properties are not assigned immediately when the node is initialized ([method Object._init]), and instead are computed and stored right before [method Node._ready].
  589. [codeblock]
  590. @onready var character_name: Label = $Label
  591. [/codeblock]
  592. </description>
  593. </annotation>
  594. <annotation name="@rpc" qualifiers="vararg">
  595. <return type="void" />
  596. <param index="0" name="mode" type="String" default="&quot;authority&quot;" />
  597. <param index="1" name="sync" type="String" default="&quot;call_remote&quot;" />
  598. <param index="2" name="transfer_mode" type="String" default="&quot;unreliable&quot;" />
  599. <param index="3" name="transfer_channel" type="int" default="0" />
  600. <description>
  601. Mark the following method for remote procedure calls. See [url=$DOCS_URL/tutorials/networking/high_level_multiplayer.html]High-level multiplayer[/url].
  602. The order of [code]mode[/code], [code]sync[/code] and [code]transfer_mode[/code] does not matter and all arguments can be omitted, but [code]transfer_channel[/code] always has to be the last argument. The accepted values for [code]mode[/code] are [code]"any_peer"[/code] or [code]"authority"[/code], for [code]sync[/code] are [code]"call_remote"[/code] or [code]"call_local"[/code] and for [code]transfer_mode[/code] are [code]"unreliable"[/code], [code]"unreliable_ordered"[/code] or [code]"reliable"[/code].
  603. [codeblock]
  604. @rpc
  605. func fn(): pass
  606. @rpc("any_peer", "unreliable_ordered")
  607. func fn_update_pos(): pass
  608. @rpc("authority", "call_remote", "unreliable", 0) # Equivalent to @rpc
  609. func fn_default(): pass
  610. [/codeblock]
  611. </description>
  612. </annotation>
  613. <annotation name="@tool">
  614. <return type="void" />
  615. <description>
  616. Mark the current script as a tool script, allowing it to be loaded and executed by the editor. See [url=$DOCS_URL/tutorials/plugins/running_code_in_the_editor.html]Running code in the editor[/url].
  617. [codeblock]
  618. @tool
  619. extends Node
  620. [/codeblock]
  621. [b]Note:[/b] As annotations describe their subject, the [code]@tool[/code] annotation must be placed before the class definition and inheritance.
  622. </description>
  623. </annotation>
  624. <annotation name="@warning_ignore" qualifiers="vararg">
  625. <return type="void" />
  626. <param index="0" name="warning" type="String" />
  627. <description>
  628. Mark the following statement to ignore the specified [param warning]. See [url=$DOCS_URL/tutorials/scripting/gdscript/warning_system.html]GDScript warning system[/url].
  629. [codeblock]
  630. func test():
  631. print("hello")
  632. return
  633. @warning_ignore("unreachable_code")
  634. print("unreachable")
  635. [/codeblock]
  636. </description>
  637. </annotation>
  638. </annotations>
  639. </class>