class_@gdscript.rst 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the @GDScript.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_@GDScript:
  5. @GDScript
  6. =========
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Built-in GDScript functions.
  11. Member Functions
  12. ----------------
  13. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`Color<class_color>` | :ref:`Color8<class_@GDScript_Color8>` **(** :ref:`int<class_int>` r8, :ref:`int<class_int>` g8, :ref:`int<class_int>` b8, :ref:`int<class_int>` a8=255 **)** |
  15. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`Color<class_color>` | :ref:`ColorN<class_@GDScript_ColorN>` **(** :ref:`String<class_string>` name, :ref:`float<class_float>` alpha=1.0 **)** |
  17. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`float<class_float>` | :ref:`abs<class_@GDScript_abs>` **(** :ref:`float<class_float>` s **)** |
  19. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`float<class_float>` | :ref:`acos<class_@GDScript_acos>` **(** :ref:`float<class_float>` s **)** |
  21. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`float<class_float>` | :ref:`asin<class_@GDScript_asin>` **(** :ref:`float<class_float>` s **)** |
  23. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | void | :ref:`assert<class_@GDScript_assert>` **(** :ref:`bool<class_bool>` condition **)** |
  25. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`float<class_float>` | :ref:`atan<class_@GDScript_atan>` **(** :ref:`float<class_float>` s **)** |
  27. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`float<class_float>` | :ref:`atan2<class_@GDScript_atan2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  29. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Variant<class_variant>` | :ref:`bytes2var<class_@GDScript_bytes2var>` **(** :ref:`PoolByteArray<class_poolbytearray>` bytes **)** |
  31. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Vector2<class_vector2>` | :ref:`cartesian2polar<class_@GDScript_cartesian2polar>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  33. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`float<class_float>` | :ref:`ceil<class_@GDScript_ceil>` **(** :ref:`float<class_float>` s **)** |
  35. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`String<class_string>` | :ref:`char<class_@GDScript_char>` **(** :ref:`int<class_int>` ascii **)** |
  37. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`float<class_float>` | :ref:`clamp<class_@GDScript_clamp>` **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)** |
  39. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Object<class_object>` | :ref:`convert<class_@GDScript_convert>` **(** :ref:`Variant<class_variant>` what, :ref:`int<class_int>` type **)** |
  41. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`float<class_float>` | :ref:`cos<class_@GDScript_cos>` **(** :ref:`float<class_float>` s **)** |
  43. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`float<class_float>` | :ref:`cosh<class_@GDScript_cosh>` **(** :ref:`float<class_float>` s **)** |
  45. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`float<class_float>` | :ref:`db2linear<class_@GDScript_db2linear>` **(** :ref:`float<class_float>` db **)** |
  47. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`float<class_float>` | :ref:`decimals<class_@GDScript_decimals>` **(** :ref:`float<class_float>` step **)** |
  49. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`float<class_float>` | :ref:`dectime<class_@GDScript_dectime>` **(** :ref:`float<class_float>` value, :ref:`float<class_float>` amount, :ref:`float<class_float>` step **)** |
  51. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`float<class_float>` | :ref:`deg2rad<class_@GDScript_deg2rad>` **(** :ref:`float<class_float>` deg **)** |
  53. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Object<class_object>` | :ref:`dict2inst<class_@GDScript_dict2inst>` **(** :ref:`Dictionary<class_dictionary>` dict **)** |
  55. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`float<class_float>` | :ref:`ease<class_@GDScript_ease>` **(** :ref:`float<class_float>` s, :ref:`float<class_float>` curve **)** |
  57. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`float<class_float>` | :ref:`exp<class_@GDScript_exp>` **(** :ref:`float<class_float>` s **)** |
  59. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`float<class_float>` | :ref:`floor<class_@GDScript_floor>` **(** :ref:`float<class_float>` s **)** |
  61. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`float<class_float>` | :ref:`fmod<class_@GDScript_fmod>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  63. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`float<class_float>` | :ref:`fposmod<class_@GDScript_fposmod>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  65. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Object<class_object>` | :ref:`funcref<class_@GDScript_funcref>` **(** :ref:`Object<class_object>` instance, :ref:`String<class_string>` funcname **)** |
  67. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`int<class_int>` | :ref:`hash<class_@GDScript_hash>` **(** :ref:`Variant<class_variant>` var **)** |
  69. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Dictionary<class_dictionary>` | :ref:`inst2dict<class_@GDScript_inst2dict>` **(** :ref:`Object<class_object>` inst **)** |
  71. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Object<class_object>` | :ref:`instance_from_id<class_@GDScript_instance_from_id>` **(** :ref:`int<class_int>` instance_id **)** |
  73. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`float<class_float>` | :ref:`inverse_lerp<class_@GDScript_inverse_lerp>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)** |
  75. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`bool<class_bool>` | :ref:`is_inf<class_@GDScript_is_inf>` **(** :ref:`float<class_float>` s **)** |
  77. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`bool<class_bool>` | :ref:`is_nan<class_@GDScript_is_nan>` **(** :ref:`float<class_float>` s **)** |
  79. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`int<class_int>` | :ref:`len<class_@GDScript_len>` **(** :ref:`Variant<class_variant>` var **)** |
  81. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`float<class_float>` | :ref:`lerp<class_@GDScript_lerp>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)** |
  83. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`float<class_float>` | :ref:`linear2db<class_@GDScript_linear2db>` **(** :ref:`float<class_float>` nrg **)** |
  85. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`Object<class_object>` | :ref:`load<class_@GDScript_load>` **(** :ref:`String<class_string>` path **)** |
  87. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`float<class_float>` | :ref:`log<class_@GDScript_log>` **(** :ref:`float<class_float>` s **)** |
  89. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`float<class_float>` | :ref:`max<class_@GDScript_max>` **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)** |
  91. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`float<class_float>` | :ref:`min<class_@GDScript_min>` **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)** |
  93. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`int<class_int>` | :ref:`nearest_po2<class_@GDScript_nearest_po2>` **(** :ref:`int<class_int>` value **)** |
  95. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`Variant<class_variant>` | :ref:`parse_json<class_@GDScript_parse_json>` **(** :ref:`String<class_string>` json **)** |
  97. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Vector2<class_vector2>` | :ref:`polar2cartesian<class_@GDScript_polar2cartesian>` **(** :ref:`float<class_float>` r, :ref:`float<class_float>` th **)** |
  99. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`float<class_float>` | :ref:`pow<class_@GDScript_pow>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  101. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`Resource<class_resource>` | :ref:`preload<class_@GDScript_preload>` **(** :ref:`String<class_string>` path **)** |
  103. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | void | :ref:`print<class_@GDScript_print>` **(** **)** vararg |
  105. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | void | :ref:`print_stack<class_@GDScript_print_stack>` **(** **)** |
  107. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | void | :ref:`printerr<class_@GDScript_printerr>` **(** **)** vararg |
  109. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | void | :ref:`printraw<class_@GDScript_printraw>` **(** **)** vararg |
  111. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | void | :ref:`prints<class_@GDScript_prints>` **(** **)** vararg |
  113. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | void | :ref:`printt<class_@GDScript_printt>` **(** **)** vararg |
  115. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`float<class_float>` | :ref:`rad2deg<class_@GDScript_rad2deg>` **(** :ref:`float<class_float>` rad **)** |
  117. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`float<class_float>` | :ref:`rand_range<class_@GDScript_rand_range>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to **)** |
  119. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`Array<class_array>` | :ref:`rand_seed<class_@GDScript_rand_seed>` **(** :ref:`int<class_int>` seed **)** |
  121. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`float<class_float>` | :ref:`randf<class_@GDScript_randf>` **(** **)** |
  123. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`int<class_int>` | :ref:`randi<class_@GDScript_randi>` **(** **)** |
  125. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | void | :ref:`randomize<class_@GDScript_randomize>` **(** **)** |
  127. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | :ref:`Array<class_array>` | :ref:`range<class_@GDScript_range>` **(** **)** vararg |
  129. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`float<class_float>` | :ref:`range_lerp<class_@GDScript_range_lerp>` **(** :ref:`float<class_float>` value, :ref:`float<class_float>` istart, :ref:`float<class_float>` istop, :ref:`float<class_float>` ostart, :ref:`float<class_float>` ostop **)** |
  131. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | :ref:`float<class_float>` | :ref:`round<class_@GDScript_round>` **(** :ref:`float<class_float>` s **)** |
  133. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | void | :ref:`seed<class_@GDScript_seed>` **(** :ref:`int<class_int>` seed **)** |
  135. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | :ref:`float<class_float>` | :ref:`sign<class_@GDScript_sign>` **(** :ref:`float<class_float>` s **)** |
  137. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | :ref:`float<class_float>` | :ref:`sin<class_@GDScript_sin>` **(** :ref:`float<class_float>` s **)** |
  139. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. | :ref:`float<class_float>` | :ref:`sinh<class_@GDScript_sinh>` **(** :ref:`float<class_float>` s **)** |
  141. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  142. | :ref:`float<class_float>` | :ref:`sqrt<class_@GDScript_sqrt>` **(** :ref:`float<class_float>` s **)** |
  143. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  144. | :ref:`float<class_float>` | :ref:`stepify<class_@GDScript_stepify>` **(** :ref:`float<class_float>` s, :ref:`float<class_float>` step **)** |
  145. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  146. | :ref:`String<class_string>` | :ref:`str<class_@GDScript_str>` **(** **)** vararg |
  147. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  148. | :ref:`Variant<class_variant>` | :ref:`str2var<class_@GDScript_str2var>` **(** :ref:`String<class_string>` string **)** |
  149. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  150. | :ref:`float<class_float>` | :ref:`tan<class_@GDScript_tan>` **(** :ref:`float<class_float>` s **)** |
  151. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  152. | :ref:`float<class_float>` | :ref:`tanh<class_@GDScript_tanh>` **(** :ref:`float<class_float>` s **)** |
  153. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  154. | :ref:`String<class_string>` | :ref:`to_json<class_@GDScript_to_json>` **(** :ref:`Variant<class_variant>` var **)** |
  155. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  156. | :ref:`bool<class_bool>` | :ref:`type_exists<class_@GDScript_type_exists>` **(** :ref:`String<class_string>` type **)** |
  157. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  158. | :ref:`int<class_int>` | :ref:`typeof<class_@GDScript_typeof>` **(** :ref:`Variant<class_variant>` what **)** |
  159. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  160. | :ref:`String<class_string>` | :ref:`validate_json<class_@GDScript_validate_json>` **(** :ref:`String<class_string>` json **)** |
  161. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  162. | :ref:`PoolByteArray<class_poolbytearray>` | :ref:`var2bytes<class_@GDScript_var2bytes>` **(** :ref:`Variant<class_variant>` var **)** |
  163. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  164. | :ref:`String<class_string>` | :ref:`var2str<class_@GDScript_var2str>` **(** :ref:`Variant<class_variant>` var **)** |
  165. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  166. | :ref:`Object<class_object>` | :ref:`weakref<class_@GDScript_weakref>` **(** :ref:`Object<class_object>` obj **)** |
  167. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  168. | :ref:`float<class_float>` | :ref:`wrapf<class_@GDScript_wrapf>` **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)** |
  169. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  170. | :ref:`int<class_int>` | :ref:`wrapi<class_@GDScript_wrapi>` **(** :ref:`int<class_int>` value, :ref:`int<class_int>` min, :ref:`int<class_int>` max **)** |
  171. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  172. | :ref:`GDScriptFunctionState<class_gdscriptfunctionstate>` | :ref:`yield<class_@GDScript_yield>` **(** :ref:`Object<class_object>` object=null, :ref:`String<class_string>` signal="" **)** |
  173. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  174. Numeric Constants
  175. -----------------
  176. - **PI** = **3.141593** --- Constant that represents how many times the diameter of a circle fits around its perimeter.
  177. - **TAU** = **6.283185** --- The circle constant, the circumference of the unit circle.
  178. - **INF** = **inf** --- A positive infinity. (For negative infinity, use -INF).
  179. - **NAN** = **nan** --- Macro constant that expands to an expression of type float that represents a NaN.
  180. The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0.
  181. Description
  182. -----------
  183. This contains the list of built-in gdscript functions. Mostly math functions and other utilities. Everything else is expanded by objects.
  184. Member Function Description
  185. ---------------------------
  186. .. _class_@GDScript_Color8:
  187. - :ref:`Color<class_color>` **Color8** **(** :ref:`int<class_int>` r8, :ref:`int<class_int>` g8, :ref:`int<class_int>` b8, :ref:`int<class_int>` a8=255 **)**
  188. Returns a 32 bit color with red, green, blue and alpha channels. Each channel has 8 bits of information ranging from 0 to 255.
  189. ``r8`` red channel
  190. ``g8`` green channel
  191. ``b8`` blue channel
  192. ``a8`` alpha channel
  193. ::
  194. red = Color8(255, 0, 0)
  195. .. _class_@GDScript_ColorN:
  196. - :ref:`Color<class_color>` **ColorN** **(** :ref:`String<class_string>` name, :ref:`float<class_float>` alpha=1.0 **)**
  197. Returns a color according to the standardised ``name`` with ``alpha`` ranging from 0 to 1.
  198. ::
  199. red = ColorN("red", 1)
  200. Supported color names:
  201. "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflower", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod", "gray", "webgray", "green", "webgreen", "greenyellow", "honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", "lightcyan", "lightgoldenrod", "lightgray", "lightgreen", "lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", "webmaroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite", "navyblue", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "purple", "webpurple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen".
  202. .. _class_@GDScript_abs:
  203. - :ref:`float<class_float>` **abs** **(** :ref:`float<class_float>` s **)**
  204. Returns the absolute value of parameter ``s`` (i.e. unsigned value, works for integer and float).
  205. ::
  206. # a is 1
  207. a = abs(-1)
  208. .. _class_@GDScript_acos:
  209. - :ref:`float<class_float>` **acos** **(** :ref:`float<class_float>` s **)**
  210. Returns the arc cosine of ``s`` in radians. Use to get the angle of cosine ``s``.
  211. ::
  212. # c is 0.523599 or 30 degrees if converted with rad2deg(s)
  213. c = acos(0.866025)
  214. .. _class_@GDScript_asin:
  215. - :ref:`float<class_float>` **asin** **(** :ref:`float<class_float>` s **)**
  216. Returns the arc sine of ``s`` in radians. Use to get the angle of sine ``s``.
  217. ::
  218. # s is 0.523599 or 30 degrees if converted with rad2deg(s)
  219. s = asin(0.5)
  220. .. _class_@GDScript_assert:
  221. - void **assert** **(** :ref:`bool<class_bool>` condition **)**
  222. Assert that the ``condition`` is true. If the ``condition`` is false a fatal error is generated and the program is halted. Useful for debugging to make sure a value is always true.
  223. ::
  224. # Speed should always be between 0 and 20
  225. speed = -10
  226. assert(speed < 20) # Is true and program continues
  227. assert(speed >= 0) # Is false and program stops
  228. assert(speed >= 0 && speed < 20) # Or combined
  229. .. _class_@GDScript_atan:
  230. - :ref:`float<class_float>` **atan** **(** :ref:`float<class_float>` s **)**
  231. Returns the arc tangent of ``s`` in radians. Use it to get the angle from an angle's tangent in trigonometry: ``atan(tan(angle)) == angle``.
  232. The method cannot know in which quadrant the angle should fall. See :ref:`atan2<class_@GDScript_atan2>` if you always want an exact angle.
  233. ::
  234. a = atan(0.5) # a is 0.463648
  235. .. _class_@GDScript_atan2:
  236. - :ref:`float<class_float>` **atan2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  237. Returns the arc tangent of ``y/x`` in radians. Use to get the angle of tangent ``y/x``. To compute the value, the method takes into account the sign of both arguments in order to determine the quadrant.
  238. ::
  239. a = atan(0,-1) # a is 3.141593
  240. .. _class_@GDScript_bytes2var:
  241. - :ref:`Variant<class_variant>` **bytes2var** **(** :ref:`PoolByteArray<class_poolbytearray>` bytes **)**
  242. Decodes a byte array back to a value.
  243. .. _class_@GDScript_cartesian2polar:
  244. - :ref:`Vector2<class_vector2>` **cartesian2polar** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  245. Converts a 2D point expressed in the cartesian coordinate system (x and y axis) to the polar coordinate system (a distance from the origin and an angle).
  246. .. _class_@GDScript_ceil:
  247. - :ref:`float<class_float>` **ceil** **(** :ref:`float<class_float>` s **)**
  248. Rounds ``s`` upward, returning the smallest integral value that is not less than ``s``.
  249. ::
  250. i = ceil(1.45) # i is 2
  251. i = ceil(1.001) # i is 2
  252. .. _class_@GDScript_char:
  253. - :ref:`String<class_string>` **char** **(** :ref:`int<class_int>` ascii **)**
  254. Returns a character as a String of the given ASCII code.
  255. ::
  256. # a is 'A'
  257. a = char(65)
  258. # a is 'a'
  259. a = char(65+32)
  260. .. _class_@GDScript_clamp:
  261. - :ref:`float<class_float>` **clamp** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)**
  262. Clamps ``value`` and returns a value not less than ``min`` and not more than ``max``.
  263. ::
  264. speed = 1000
  265. # a is 20
  266. a = clamp(speed, 1, 20)
  267. speed = -10
  268. # a is 1
  269. a = clamp(speed, 1, 20)
  270. .. _class_@GDScript_convert:
  271. - :ref:`Object<class_object>` **convert** **(** :ref:`Variant<class_variant>` what, :ref:`int<class_int>` type **)**
  272. Converts from a type to another in the best way possible. The ``type`` parameter uses the enum TYPE\_\* in :ref:`@GlobalScope<class_@globalscope>`.
  273. ::
  274. a = Vector2(1, 0)
  275. # prints 1
  276. print(a.length())
  277. a = convert(a, TYPE_STRING)
  278. # prints 6
  279. # (1, 0) is 6 characters
  280. print(a.length())
  281. .. _class_@GDScript_cos:
  282. - :ref:`float<class_float>` **cos** **(** :ref:`float<class_float>` s **)**
  283. Returns the cosine of angle ``s`` in radians.
  284. ::
  285. # prints 1 and -1
  286. print(cos(PI*2))
  287. print(cos(PI))
  288. .. _class_@GDScript_cosh:
  289. - :ref:`float<class_float>` **cosh** **(** :ref:`float<class_float>` s **)**
  290. Returns the hyperbolic cosine of ``s`` in radians.
  291. ::
  292. # prints 1.543081
  293. print(cosh(1))
  294. .. _class_@GDScript_db2linear:
  295. - :ref:`float<class_float>` **db2linear** **(** :ref:`float<class_float>` db **)**
  296. Converts from decibels to linear energy (audio).
  297. .. _class_@GDScript_decimals:
  298. - :ref:`float<class_float>` **decimals** **(** :ref:`float<class_float>` step **)**
  299. Returns the position of the first non-zero digit, after the decimal point.
  300. ::
  301. # n is 2
  302. n = decimals(0.035)
  303. .. _class_@GDScript_dectime:
  304. - :ref:`float<class_float>` **dectime** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` amount, :ref:`float<class_float>` step **)**
  305. Returns the result of ``value`` decreased by ``step`` \* ``amount``.
  306. ::
  307. # a = 59
  308. a = dectime(60, 10, 0.1))
  309. .. _class_@GDScript_deg2rad:
  310. - :ref:`float<class_float>` **deg2rad** **(** :ref:`float<class_float>` deg **)**
  311. Returns degrees converted to radians.
  312. ::
  313. # r is 3.141593
  314. r = deg2rad(180)
  315. .. _class_@GDScript_dict2inst:
  316. - :ref:`Object<class_object>` **dict2inst** **(** :ref:`Dictionary<class_dictionary>` dict **)**
  317. Converts a previously converted instance to a dictionary, back into an instance. Useful for deserializing.
  318. .. _class_@GDScript_ease:
  319. - :ref:`float<class_float>` **ease** **(** :ref:`float<class_float>` s, :ref:`float<class_float>` curve **)**
  320. Easing function, based on exponent. 0 is constant, 1 is linear, 0 to 1 is ease-in, 1+ is ease out. Negative values are in-out/out in.
  321. .. _class_@GDScript_exp:
  322. - :ref:`float<class_float>` **exp** **(** :ref:`float<class_float>` s **)**
  323. The natural exponential function. It raises the mathematical constant **e** to the power of ``s`` and returns it.
  324. **e** has an approximate value of 2.71828.
  325. ::
  326. a = exp(2) # approximately 7.39
  327. .. _class_@GDScript_floor:
  328. - :ref:`float<class_float>` **floor** **(** :ref:`float<class_float>` s **)**
  329. Rounds ``s`` to the closest smaller integer and returns it.
  330. ::
  331. # a is 2
  332. a = floor(2.99)
  333. # a is -3
  334. a = floor(-2.99)
  335. .. _class_@GDScript_fmod:
  336. - :ref:`float<class_float>` **fmod** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  337. Returns the floating-point remainder of ``x/y``.
  338. ::
  339. # remainder is 1.5
  340. var remainder = fmod(7, 5.5)
  341. .. _class_@GDScript_fposmod:
  342. - :ref:`float<class_float>` **fposmod** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  343. Returns the floating-point remainder of ``x/y`` that wraps equally in positive and negative.
  344. ::
  345. var i = -10;
  346. while i < 0:
  347. prints(i, fposmod(i, 10))
  348. i += 1
  349. Produces:
  350. ::
  351. -10 10
  352. -9 1
  353. -8 2
  354. -7 3
  355. -6 4
  356. -5 5
  357. -4 6
  358. -3 7
  359. -2 8
  360. -1 9
  361. .. _class_@GDScript_funcref:
  362. - :ref:`Object<class_object>` **funcref** **(** :ref:`Object<class_object>` instance, :ref:`String<class_string>` funcname **)**
  363. Returns a reference to the specified function ``funcname`` in the ``instance`` node. As functions aren't first-class objects in GDscript, use ``funcref`` to store a :ref:`FuncRef<class_funcref>` in a variable and call it later.
  364. ::
  365. func foo():
  366. return("bar")
  367. a = funcref(self, "foo")
  368. print(a.call_func()) # prints bar
  369. .. _class_@GDScript_hash:
  370. - :ref:`int<class_int>` **hash** **(** :ref:`Variant<class_variant>` var **)**
  371. Returns the integer hash of the variable passed.
  372. ::
  373. print(hash("a")) # prints 177670
  374. .. _class_@GDScript_inst2dict:
  375. - :ref:`Dictionary<class_dictionary>` **inst2dict** **(** :ref:`Object<class_object>` inst **)**
  376. Returns the passed instance converted to a dictionary (useful for serializing).
  377. ::
  378. var foo = "bar"
  379. func _ready():
  380. var d = inst2dict(self)
  381. print(d.keys())
  382. print(d.values())
  383. Prints out:
  384. ::
  385. [@subpath, @path, foo]
  386. [, res://test.gd, bar]
  387. .. _class_@GDScript_instance_from_id:
  388. - :ref:`Object<class_object>` **instance_from_id** **(** :ref:`int<class_int>` instance_id **)**
  389. Returns the Object that corresponds to ``instance_id``. All Objects have a unique instance ID.
  390. ::
  391. var foo = "bar"
  392. func _ready():
  393. var id = get_instance_id()
  394. var inst = instance_from_id(id)
  395. print(inst.foo) # prints bar
  396. .. _class_@GDScript_inverse_lerp:
  397. - :ref:`float<class_float>` **inverse_lerp** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)**
  398. Returns a normalized value considering the given range.
  399. ::
  400. inverse_lerp(3, 5, 4) # returns 0.5
  401. .. _class_@GDScript_is_inf:
  402. - :ref:`bool<class_bool>` **is_inf** **(** :ref:`float<class_float>` s **)**
  403. Returns True/False whether ``s`` is an infinity value (either positive infinity or negative infinity).
  404. .. _class_@GDScript_is_nan:
  405. - :ref:`bool<class_bool>` **is_nan** **(** :ref:`float<class_float>` s **)**
  406. Returns True/False whether ``s`` is a NaN (Not-A-Number) value.
  407. .. _class_@GDScript_len:
  408. - :ref:`int<class_int>` **len** **(** :ref:`Variant<class_variant>` var **)**
  409. Returns length of Variant ``var``. Length is the character count of String, element count of Array, size of Dictionary, etc. Note: Generates a fatal error if Variant can not provide a length.
  410. ::
  411. a = [1, 2, 3, 4]
  412. len(a) # returns 4
  413. .. _class_@GDScript_lerp:
  414. - :ref:`float<class_float>` **lerp** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)**
  415. Linearly interpolates between two values by a normalized value.
  416. ::
  417. lerp(1, 3, 0.5) # returns 2
  418. .. _class_@GDScript_linear2db:
  419. - :ref:`float<class_float>` **linear2db** **(** :ref:`float<class_float>` nrg **)**
  420. Converts from linear energy to decibels (audio).
  421. .. _class_@GDScript_load:
  422. - :ref:`Object<class_object>` **load** **(** :ref:`String<class_string>` path **)**
  423. Loads a resource from the filesystem located at ``path``. Note: resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path".
  424. ::
  425. # load a scene called main located in the root of the project directory
  426. var main = load("res://main.tscn")
  427. .. _class_@GDScript_log:
  428. - :ref:`float<class_float>` **log** **(** :ref:`float<class_float>` s **)**
  429. Natural logarithm. The amount of time needed to reach a certain level of continuous growth. Note: This is not the same as the log function on your calculator which is a base 10 logarithm.
  430. ::
  431. log(10) # returns 2.302585
  432. .. _class_@GDScript_max:
  433. - :ref:`float<class_float>` **max** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
  434. Returns the maximum of two values.
  435. ::
  436. max(1,2) # returns 2
  437. max(-3.99, -4) # returns -3.99
  438. .. _class_@GDScript_min:
  439. - :ref:`float<class_float>` **min** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
  440. Returns the minimum of two values.
  441. ::
  442. min(1,2) # returns 1
  443. min(-3.99, -4) # returns -4
  444. .. _class_@GDScript_nearest_po2:
  445. - :ref:`int<class_int>` **nearest_po2** **(** :ref:`int<class_int>` value **)**
  446. Returns the nearest larger power of 2 for integer ``value``.
  447. ::
  448. nearest_po2(3) # returns 4
  449. nearest_po2(4) # returns 4
  450. nearest_po2(5) # returns 8
  451. .. _class_@GDScript_parse_json:
  452. - :ref:`Variant<class_variant>` **parse_json** **(** :ref:`String<class_string>` json **)**
  453. Parse JSON text to a Variant (use :ref:`typeof<class_@GDScript_typeof>` to check if it is what you expect).
  454. Be aware that the JSON specification does not define integer or float types, but only a number type. Therefore, parsing a JSON text will convert all numerical values to :ref:`float<class_float>` types.
  455. Note that JSON objects do not preserve key order like Godot dictionaries, thus you should not rely on keys being in a certain order if a dictionary is constructed from JSON. In contrast, JSON arrays retain the order of their elements:
  456. ::
  457. p = parse_json('["a", "b", "c"]')
  458. if typeof(p) == TYPE_ARRAY:
  459. print(p[0]) # prints a
  460. else:
  461. print("unexpected results")
  462. .. _class_@GDScript_polar2cartesian:
  463. - :ref:`Vector2<class_vector2>` **polar2cartesian** **(** :ref:`float<class_float>` r, :ref:`float<class_float>` th **)**
  464. Converts a 2D point expressed in the polar coordinate system (a distance from the origin ``r`` and an angle ``th``) to the cartesian coordinate system (x and y axis).
  465. .. _class_@GDScript_pow:
  466. - :ref:`float<class_float>` **pow** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  467. Returns the result of ``x`` raised to the power of ``y``.
  468. ::
  469. pow(2,5) # returns 32
  470. .. _class_@GDScript_preload:
  471. - :ref:`Resource<class_resource>` **preload** **(** :ref:`String<class_string>` path **)**
  472. Returns a resource from the filesystem that is loaded during script parsing. Note: resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path".
  473. ::
  474. # load a scene called main located in the root of the project directory
  475. var main = preload("res://main.tscn")
  476. .. _class_@GDScript_print:
  477. - void **print** **(** **)** vararg
  478. Converts one or more arguments to strings in the best way possible and prints them to the console.
  479. ::
  480. a = [1,2,3]
  481. print("a","b",a) # prints ab[1, 2, 3]
  482. .. _class_@GDScript_print_stack:
  483. - void **print_stack** **(** **)**
  484. Prints a stack track at code location, only works when running with debugger turned on.
  485. Output in the console would look something like this:
  486. ::
  487. Frame 0 - res://test.gd:16 in function '_process'
  488. .. _class_@GDScript_printerr:
  489. - void **printerr** **(** **)** vararg
  490. Prints one or more arguments to strings in the best way possible to standard error line.
  491. ::
  492. printerr("prints to stderr")
  493. .. _class_@GDScript_printraw:
  494. - void **printraw** **(** **)** vararg
  495. Prints one or more arguments to strings in the best way possible to console. No newline is added at the end.
  496. ::
  497. printraw("A")
  498. printraw("B")
  499. # prints AB
  500. .. _class_@GDScript_prints:
  501. - void **prints** **(** **)** vararg
  502. Prints one or more arguments to the console with a space between each argument.
  503. ::
  504. prints("A", "B", "C") # prints A B C
  505. .. _class_@GDScript_printt:
  506. - void **printt** **(** **)** vararg
  507. Prints one or more arguments to the console with a tab between each argument.
  508. ::
  509. printt("A", "B", "C") # prints A B C
  510. .. _class_@GDScript_rad2deg:
  511. - :ref:`float<class_float>` **rad2deg** **(** :ref:`float<class_float>` rad **)**
  512. Converts from radians to degrees.
  513. ::
  514. rad2deg(0.523599) # returns 30
  515. .. _class_@GDScript_rand_range:
  516. - :ref:`float<class_float>` **rand_range** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to **)**
  517. Random range, any floating point value between ``from`` and ``to``.
  518. ::
  519. prints(rand_range(0, 1), rand_range(0, 1)) # prints 0.135591 0.405263
  520. .. _class_@GDScript_rand_seed:
  521. - :ref:`Array<class_array>` **rand_seed** **(** :ref:`int<class_int>` seed **)**
  522. Random from seed: pass a ``seed``, and an array with both number and new seed is returned. "Seed" here refers to the internal state of the pseudo random number generator. The internal state of the current implementation is 64 bits.
  523. .. _class_@GDScript_randf:
  524. - :ref:`float<class_float>` **randf** **(** **)**
  525. Returns a random floating point value between 0 and 1.
  526. ::
  527. randf() # returns 0.375671
  528. .. _class_@GDScript_randi:
  529. - :ref:`int<class_int>` **randi** **(** **)**
  530. Returns a random 32 bit integer. Use remainder to obtain a random value between 0 and N (where N is smaller than 2^32 -1).
  531. ::
  532. randi() % 20 # returns random number between 0 and 19
  533. randi() % 100 # returns random number between 0 and 99
  534. randi() % 100 + 1 # returns random number between 1 and 100
  535. .. _class_@GDScript_randomize:
  536. - void **randomize** **(** **)**
  537. Randomizes the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time.
  538. ::
  539. func _ready():
  540. randomize()
  541. .. _class_@GDScript_range:
  542. - :ref:`Array<class_array>` **range** **(** **)** vararg
  543. Returns an array with the given range. Range can be 1 argument N (0 to N-1), two arguments (initial, final-1) or three arguments (initial, final-1, increment).
  544. ::
  545. for i in range(4):
  546. print(i)
  547. for i in range(2, 5):
  548. print(i)
  549. for i in range(0, 6, 2):
  550. print(i)
  551. Output:
  552. ::
  553. 0
  554. 1
  555. 2
  556. 3
  557. 2
  558. 3
  559. 4
  560. 0
  561. 2
  562. 4
  563. .. _class_@GDScript_range_lerp:
  564. - :ref:`float<class_float>` **range_lerp** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` istart, :ref:`float<class_float>` istop, :ref:`float<class_float>` ostart, :ref:`float<class_float>` ostop **)**
  565. Maps a ``value`` from range ``[istart, istop]`` to ``[ostart, ostop]``.
  566. ::
  567. range_lerp(75, 0, 100, -1, 1) # returns 0.5
  568. .. _class_@GDScript_round:
  569. - :ref:`float<class_float>` **round** **(** :ref:`float<class_float>` s **)**
  570. Returns the integral value that is nearest to ``s``, with halfway cases rounded away from zero.
  571. ::
  572. round(2.6) # returns 3
  573. .. _class_@GDScript_seed:
  574. - void **seed** **(** :ref:`int<class_int>` seed **)**
  575. Sets seed for the random number generator.
  576. ::
  577. my_seed = "Godot Rocks"
  578. seed(my_seed.hash())
  579. .. _class_@GDScript_sign:
  580. - :ref:`float<class_float>` **sign** **(** :ref:`float<class_float>` s **)**
  581. Returns the sign of ``s``: -1 or 1. Returns 0 if ``s`` is 0.
  582. ::
  583. sign(-6) # returns -1
  584. sign(0) # returns 0
  585. sign(6) # returns 1
  586. .. _class_@GDScript_sin:
  587. - :ref:`float<class_float>` **sin** **(** :ref:`float<class_float>` s **)**
  588. Returns the sine of angle ``s`` in radians.
  589. ::
  590. sin(0.523599) # returns 0.5
  591. .. _class_@GDScript_sinh:
  592. - :ref:`float<class_float>` **sinh** **(** :ref:`float<class_float>` s **)**
  593. Returns the hyperbolic sine of ``s``.
  594. ::
  595. a = log(2.0) # returns 0.693147
  596. sinh(a) # returns 0.75
  597. .. _class_@GDScript_sqrt:
  598. - :ref:`float<class_float>` **sqrt** **(** :ref:`float<class_float>` s **)**
  599. Returns the square root of ``s``.
  600. ::
  601. sqrt(9) # returns 3
  602. .. _class_@GDScript_stepify:
  603. - :ref:`float<class_float>` **stepify** **(** :ref:`float<class_float>` s, :ref:`float<class_float>` step **)**
  604. Snaps float value ``s`` to a given ``step``.
  605. .. _class_@GDScript_str:
  606. - :ref:`String<class_string>` **str** **(** **)** vararg
  607. Converts one or more arguments to string in the best way possible.
  608. ::
  609. var a = [10, 20, 30]
  610. var b = str(a);
  611. len(a) # returns 3
  612. len(b) # returns 12
  613. .. _class_@GDScript_str2var:
  614. - :ref:`Variant<class_variant>` **str2var** **(** :ref:`String<class_string>` string **)**
  615. Converts a formatted string that was returned by :ref:`var2str<class_@GDScript_var2str>` to the original value.
  616. ::
  617. a = '{ "a": 1, "b": 2 }'
  618. b = str2var(a)
  619. print(b['a']) # prints 1
  620. .. _class_@GDScript_tan:
  621. - :ref:`float<class_float>` **tan** **(** :ref:`float<class_float>` s **)**
  622. Returns the tangent of angle ``s`` in radians.
  623. ::
  624. tan( deg2rad(45) ) # returns 1
  625. .. _class_@GDScript_tanh:
  626. - :ref:`float<class_float>` **tanh** **(** :ref:`float<class_float>` s **)**
  627. Returns the hyperbolic tangent of ``s``.
  628. ::
  629. a = log(2.0) # returns 0.693147
  630. tanh(a) # returns 0.6
  631. .. _class_@GDScript_to_json:
  632. - :ref:`String<class_string>` **to_json** **(** :ref:`Variant<class_variant>` var **)**
  633. Converts a Variant ``var`` to JSON text and return the result. Useful for serializing data to store or send over the network.
  634. ::
  635. a = { 'a': 1, 'b': 2 }
  636. b = to_json(a)
  637. print(b) # {"a":1, "b":2}
  638. .. _class_@GDScript_type_exists:
  639. - :ref:`bool<class_bool>` **type_exists** **(** :ref:`String<class_string>` type **)**
  640. Returns whether the given class exists in :ref:`ClassDB<class_classdb>`.
  641. ::
  642. type_exists("Sprite") # returns true
  643. type_exists("Variant") # returns false
  644. .. _class_@GDScript_typeof:
  645. - :ref:`int<class_int>` **typeof** **(** :ref:`Variant<class_variant>` what **)**
  646. Returns the internal type of the given Variant object, using the TYPE\_\* enum in :ref:`@GlobalScope<class_@globalscope>`.
  647. ::
  648. p = parse_json('["a", "b", "c"]')
  649. if typeof(p) == TYPE_ARRAY:
  650. print(p[0]) # prints a
  651. else:
  652. print("unexpected results")
  653. .. _class_@GDScript_validate_json:
  654. - :ref:`String<class_string>` **validate_json** **(** :ref:`String<class_string>` json **)**
  655. Checks that ``json`` is valid JSON data. Returns empty string if valid. Returns error message if not valid.
  656. ::
  657. j = to_json([1, 2, 3])
  658. v = validate_json(j)
  659. if not v:
  660. print("valid")
  661. else:
  662. prints("invalid", v)
  663. .. _class_@GDScript_var2bytes:
  664. - :ref:`PoolByteArray<class_poolbytearray>` **var2bytes** **(** :ref:`Variant<class_variant>` var **)**
  665. Encodes a variable value to a byte array.
  666. .. _class_@GDScript_var2str:
  667. - :ref:`String<class_string>` **var2str** **(** :ref:`Variant<class_variant>` var **)**
  668. Converts a Variant ``var`` to a formatted string that can later be parsed using :ref:`str2var<class_@GDScript_str2var>`.
  669. ::
  670. a = { 'a': 1, 'b': 2 }
  671. print(var2str(a))
  672. prints
  673. ::
  674. {
  675. "a": 1,
  676. "b": 2
  677. }
  678. .. _class_@GDScript_weakref:
  679. - :ref:`Object<class_object>` **weakref** **(** :ref:`Object<class_object>` obj **)**
  680. Returns a weak reference to an object.
  681. A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, garbage collection is free to destroy the referent and reuse its memory for something else. However, until the object is actually destroyed the weak reference may return the object even if there are no strong references to it.
  682. .. _class_@GDScript_wrapf:
  683. - :ref:`float<class_float>` **wrapf** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)**
  684. Wraps float ``value`` between ``min`` and ``max``.
  685. Usable for creating loop-alike behavior or infinite surfaces.
  686. ::
  687. # a is 0.5
  688. a = wrapf(10.5, 0.0, 10.0)
  689. ::
  690. # a is 9.5
  691. a = wrapf(-0.5, 0.0, 10.0)
  692. ::
  693. # infinite loop between 0.0 and 0.99
  694. f = wrapf(f + 0.1, 0.0, 1.0)
  695. .. _class_@GDScript_wrapi:
  696. - :ref:`int<class_int>` **wrapi** **(** :ref:`int<class_int>` value, :ref:`int<class_int>` min, :ref:`int<class_int>` max **)**
  697. Wraps integer ``value`` between ``min`` and ``max``.
  698. Usable for creating loop-alike behavior or infinite surfaces.
  699. ::
  700. # a is 0
  701. a = wrapi(10, 0, 10)
  702. ::
  703. # a is 9
  704. a = wrapi(-1, 0, 10)
  705. ::
  706. # infinite loop between 0 and 9
  707. frame = wrapi(frame + 1, 0, 10)
  708. .. _class_@GDScript_yield:
  709. - :ref:`GDScriptFunctionState<class_gdscriptfunctionstate>` **yield** **(** :ref:`Object<class_object>` object=null, :ref:`String<class_string>` signal="" **)**
  710. Stops the function execution and returns the current state. Call :ref:`GDScriptFunctionState.resume<class_GDScriptFunctionState_resume>` on the state to resume execution. This invalidates the state.
  711. Returns anything that was passed to the resume function call. If passed an object and a signal, the execution is resumed when the object's signal is emitted.