[email protected] 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  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_instance_valid<class_@GDScript_is_instance_valid>` **(** :ref:`Object<class_object>` instance **)** |
  79. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`bool<class_bool>` | :ref:`is_nan<class_@GDScript_is_nan>` **(** :ref:`float<class_float>` s **)** |
  81. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`int<class_int>` | :ref:`len<class_@GDScript_len>` **(** :ref:`Variant<class_variant>` var **)** |
  83. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`float<class_float>` | :ref:`lerp<class_@GDScript_lerp>` **(** :ref:`Variant<class_variant>` from, :ref:`Variant<class_variant>` to, :ref:`float<class_float>` weight **)** |
  85. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`float<class_float>` | :ref:`linear2db<class_@GDScript_linear2db>` **(** :ref:`float<class_float>` nrg **)** |
  87. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Object<class_object>` | :ref:`load<class_@GDScript_load>` **(** :ref:`String<class_string>` path **)** |
  89. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`float<class_float>` | :ref:`log<class_@GDScript_log>` **(** :ref:`float<class_float>` s **)** |
  91. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`float<class_float>` | :ref:`max<class_@GDScript_max>` **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)** |
  93. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`float<class_float>` | :ref:`min<class_@GDScript_min>` **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)** |
  95. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`int<class_int>` | :ref:`nearest_po2<class_@GDScript_nearest_po2>` **(** :ref:`int<class_int>` value **)** |
  97. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Variant<class_variant>` | :ref:`parse_json<class_@GDScript_parse_json>` **(** :ref:`String<class_string>` json **)** |
  99. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`Vector2<class_vector2>` | :ref:`polar2cartesian<class_@GDScript_polar2cartesian>` **(** :ref:`float<class_float>` r, :ref:`float<class_float>` th **)** |
  101. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`float<class_float>` | :ref:`pow<class_@GDScript_pow>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  103. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`Resource<class_resource>` | :ref:`preload<class_@GDScript_preload>` **(** :ref:`String<class_string>` path **)** |
  105. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | void | :ref:`print<class_@GDScript_print>` **(** **)** vararg |
  107. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | void | :ref:`print_stack<class_@GDScript_print_stack>` **(** **)** |
  109. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | void | :ref:`printerr<class_@GDScript_printerr>` **(** **)** vararg |
  111. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | void | :ref:`printraw<class_@GDScript_printraw>` **(** **)** vararg |
  113. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | void | :ref:`prints<class_@GDScript_prints>` **(** **)** vararg |
  115. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | void | :ref:`printt<class_@GDScript_printt>` **(** **)** vararg |
  117. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`float<class_float>` | :ref:`rad2deg<class_@GDScript_rad2deg>` **(** :ref:`float<class_float>` rad **)** |
  119. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`float<class_float>` | :ref:`rand_range<class_@GDScript_rand_range>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to **)** |
  121. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`Array<class_array>` | :ref:`rand_seed<class_@GDScript_rand_seed>` **(** :ref:`int<class_int>` seed **)** |
  123. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`float<class_float>` | :ref:`randf<class_@GDScript_randf>` **(** **)** |
  125. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | :ref:`int<class_int>` | :ref:`randi<class_@GDScript_randi>` **(** **)** |
  127. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | void | :ref:`randomize<class_@GDScript_randomize>` **(** **)** |
  129. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`Array<class_array>` | :ref:`range<class_@GDScript_range>` **(** **)** vararg |
  131. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | :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 **)** |
  133. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | :ref:`float<class_float>` | :ref:`round<class_@GDScript_round>` **(** :ref:`float<class_float>` s **)** |
  135. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | void | :ref:`seed<class_@GDScript_seed>` **(** :ref:`int<class_int>` seed **)** |
  137. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | :ref:`float<class_float>` | :ref:`sign<class_@GDScript_sign>` **(** :ref:`float<class_float>` s **)** |
  139. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. | :ref:`float<class_float>` | :ref:`sin<class_@GDScript_sin>` **(** :ref:`float<class_float>` s **)** |
  141. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  142. | :ref:`float<class_float>` | :ref:`sinh<class_@GDScript_sinh>` **(** :ref:`float<class_float>` s **)** |
  143. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  144. | :ref:`float<class_float>` | :ref:`sqrt<class_@GDScript_sqrt>` **(** :ref:`float<class_float>` s **)** |
  145. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  146. | :ref:`float<class_float>` | :ref:`stepify<class_@GDScript_stepify>` **(** :ref:`float<class_float>` s, :ref:`float<class_float>` step **)** |
  147. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  148. | :ref:`String<class_string>` | :ref:`str<class_@GDScript_str>` **(** **)** vararg |
  149. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  150. | :ref:`Variant<class_variant>` | :ref:`str2var<class_@GDScript_str2var>` **(** :ref:`String<class_string>` string **)** |
  151. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  152. | :ref:`float<class_float>` | :ref:`tan<class_@GDScript_tan>` **(** :ref:`float<class_float>` s **)** |
  153. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  154. | :ref:`float<class_float>` | :ref:`tanh<class_@GDScript_tanh>` **(** :ref:`float<class_float>` s **)** |
  155. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  156. | :ref:`String<class_string>` | :ref:`to_json<class_@GDScript_to_json>` **(** :ref:`Variant<class_variant>` var **)** |
  157. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  158. | :ref:`bool<class_bool>` | :ref:`type_exists<class_@GDScript_type_exists>` **(** :ref:`String<class_string>` type **)** |
  159. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  160. | :ref:`int<class_int>` | :ref:`typeof<class_@GDScript_typeof>` **(** :ref:`Variant<class_variant>` what **)** |
  161. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  162. | :ref:`String<class_string>` | :ref:`validate_json<class_@GDScript_validate_json>` **(** :ref:`String<class_string>` json **)** |
  163. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  164. | :ref:`PoolByteArray<class_poolbytearray>` | :ref:`var2bytes<class_@GDScript_var2bytes>` **(** :ref:`Variant<class_variant>` var **)** |
  165. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  166. | :ref:`String<class_string>` | :ref:`var2str<class_@GDScript_var2str>` **(** :ref:`Variant<class_variant>` var **)** |
  167. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  168. | :ref:`Object<class_object>` | :ref:`weakref<class_@GDScript_weakref>` **(** :ref:`Object<class_object>` obj **)** |
  169. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  170. | :ref:`float<class_float>` | :ref:`wrapf<class_@GDScript_wrapf>` **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)** |
  171. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  172. | :ref:`int<class_int>` | :ref:`wrapi<class_@GDScript_wrapi>` **(** :ref:`int<class_int>` value, :ref:`int<class_int>` min, :ref:`int<class_int>` max **)** |
  173. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  174. | :ref:`GDScriptFunctionState<class_gdscriptfunctionstate>` | :ref:`yield<class_@GDScript_yield>` **(** :ref:`Object<class_object>` object=null, :ref:`String<class_string>` signal="" **)** |
  175. +------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  176. Numeric Constants
  177. -----------------
  178. - **PI** = **3.141593** --- Constant that represents how many times the diameter of a circle fits around its perimeter.
  179. - **TAU** = **6.283185** --- The circle constant, the circumference of the unit circle.
  180. - **INF** = **inf** --- A positive infinity. (For negative infinity, use -INF).
  181. - **NAN** = **nan** --- Macro constant that expands to an expression of type float that represents a NaN.
  182. 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.
  183. Description
  184. -----------
  185. This contains the list of built-in gdscript functions. Mostly math functions and other utilities. Everything else is expanded by objects.
  186. Member Function Description
  187. ---------------------------
  188. .. _class_@GDScript_Color8:
  189. - :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 **)**
  190. Returns a 32 bit color with red, green, blue and alpha channels. Each channel has 8 bits of information ranging from 0 to 255.
  191. ``r8`` red channel
  192. ``g8`` green channel
  193. ``b8`` blue channel
  194. ``a8`` alpha channel
  195. ::
  196. red = Color8(255, 0, 0)
  197. .. _class_@GDScript_ColorN:
  198. - :ref:`Color<class_color>` **ColorN** **(** :ref:`String<class_string>` name, :ref:`float<class_float>` alpha=1.0 **)**
  199. Returns a color according to the standardised ``name`` with ``alpha`` ranging from 0 to 1.
  200. ::
  201. red = ColorN("red", 1)
  202. Supported color names:
  203. "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".
  204. .. _class_@GDScript_abs:
  205. - :ref:`float<class_float>` **abs** **(** :ref:`float<class_float>` s **)**
  206. Returns the absolute value of parameter ``s`` (i.e. unsigned value, works for integer and float).
  207. ::
  208. # a is 1
  209. a = abs(-1)
  210. .. _class_@GDScript_acos:
  211. - :ref:`float<class_float>` **acos** **(** :ref:`float<class_float>` s **)**
  212. Returns the arc cosine of ``s`` in radians. Use to get the angle of cosine ``s``.
  213. ::
  214. # c is 0.523599 or 30 degrees if converted with rad2deg(s)
  215. c = acos(0.866025)
  216. .. _class_@GDScript_asin:
  217. - :ref:`float<class_float>` **asin** **(** :ref:`float<class_float>` s **)**
  218. Returns the arc sine of ``s`` in radians. Use to get the angle of sine ``s``.
  219. ::
  220. # s is 0.523599 or 30 degrees if converted with rad2deg(s)
  221. s = asin(0.5)
  222. .. _class_@GDScript_assert:
  223. - void **assert** **(** :ref:`bool<class_bool>` condition **)**
  224. 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.
  225. ::
  226. # Speed should always be between 0 and 20
  227. speed = -10
  228. assert(speed < 20) # Is true and program continues
  229. assert(speed >= 0) # Is false and program stops
  230. assert(speed >= 0 && speed < 20) # Or combined
  231. .. _class_@GDScript_atan:
  232. - :ref:`float<class_float>` **atan** **(** :ref:`float<class_float>` s **)**
  233. 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``.
  234. The method cannot know in which quadrant the angle should fall. See :ref:`atan2<class_@GDScript_atan2>` if you always want an exact angle.
  235. ::
  236. a = atan(0.5) # a is 0.463648
  237. .. _class_@GDScript_atan2:
  238. - :ref:`float<class_float>` **atan2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  239. 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.
  240. ::
  241. a = atan(0,-1) # a is 3.141593
  242. .. _class_@GDScript_bytes2var:
  243. - :ref:`Variant<class_variant>` **bytes2var** **(** :ref:`PoolByteArray<class_poolbytearray>` bytes **)**
  244. Decodes a byte array back to a value.
  245. .. _class_@GDScript_cartesian2polar:
  246. - :ref:`Vector2<class_vector2>` **cartesian2polar** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  247. 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).
  248. .. _class_@GDScript_ceil:
  249. - :ref:`float<class_float>` **ceil** **(** :ref:`float<class_float>` s **)**
  250. Rounds ``s`` upward, returning the smallest integral value that is not less than ``s``.
  251. ::
  252. i = ceil(1.45) # i is 2
  253. i = ceil(1.001) # i is 2
  254. .. _class_@GDScript_char:
  255. - :ref:`String<class_string>` **char** **(** :ref:`int<class_int>` ascii **)**
  256. Returns a character as a String of the given ASCII code.
  257. ::
  258. # a is 'A'
  259. a = char(65)
  260. # a is 'a'
  261. a = char(65+32)
  262. .. _class_@GDScript_clamp:
  263. - :ref:`float<class_float>` **clamp** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)**
  264. Clamps ``value`` and returns a value not less than ``min`` and not more than ``max``.
  265. ::
  266. speed = 1000
  267. # a is 20
  268. a = clamp(speed, 1, 20)
  269. speed = -10
  270. # a is 1
  271. a = clamp(speed, 1, 20)
  272. .. _class_@GDScript_convert:
  273. - :ref:`Object<class_object>` **convert** **(** :ref:`Variant<class_variant>` what, :ref:`int<class_int>` type **)**
  274. Converts from a type to another in the best way possible. The ``type`` parameter uses the enum TYPE\_\* in :ref:`@GlobalScope<class_@globalscope>`.
  275. ::
  276. a = Vector2(1, 0)
  277. # prints 1
  278. print(a.length())
  279. a = convert(a, TYPE_STRING)
  280. # prints 6
  281. # (1, 0) is 6 characters
  282. print(a.length())
  283. .. _class_@GDScript_cos:
  284. - :ref:`float<class_float>` **cos** **(** :ref:`float<class_float>` s **)**
  285. Returns the cosine of angle ``s`` in radians.
  286. ::
  287. # prints 1 and -1
  288. print(cos(PI*2))
  289. print(cos(PI))
  290. .. _class_@GDScript_cosh:
  291. - :ref:`float<class_float>` **cosh** **(** :ref:`float<class_float>` s **)**
  292. Returns the hyperbolic cosine of ``s`` in radians.
  293. ::
  294. # prints 1.543081
  295. print(cosh(1))
  296. .. _class_@GDScript_db2linear:
  297. - :ref:`float<class_float>` **db2linear** **(** :ref:`float<class_float>` db **)**
  298. Converts from decibels to linear energy (audio).
  299. .. _class_@GDScript_decimals:
  300. - :ref:`float<class_float>` **decimals** **(** :ref:`float<class_float>` step **)**
  301. Returns the position of the first non-zero digit, after the decimal point.
  302. ::
  303. # n is 2
  304. n = decimals(0.035)
  305. .. _class_@GDScript_dectime:
  306. - :ref:`float<class_float>` **dectime** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` amount, :ref:`float<class_float>` step **)**
  307. Returns the result of ``value`` decreased by ``step`` \* ``amount``.
  308. ::
  309. # a = 59
  310. a = dectime(60, 10, 0.1))
  311. .. _class_@GDScript_deg2rad:
  312. - :ref:`float<class_float>` **deg2rad** **(** :ref:`float<class_float>` deg **)**
  313. Returns degrees converted to radians.
  314. ::
  315. # r is 3.141593
  316. r = deg2rad(180)
  317. .. _class_@GDScript_dict2inst:
  318. - :ref:`Object<class_object>` **dict2inst** **(** :ref:`Dictionary<class_dictionary>` dict **)**
  319. Converts a previously converted instance to a dictionary, back into an instance. Useful for deserializing.
  320. .. _class_@GDScript_ease:
  321. - :ref:`float<class_float>` **ease** **(** :ref:`float<class_float>` s, :ref:`float<class_float>` curve **)**
  322. 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.
  323. .. _class_@GDScript_exp:
  324. - :ref:`float<class_float>` **exp** **(** :ref:`float<class_float>` s **)**
  325. The natural exponential function. It raises the mathematical constant **e** to the power of ``s`` and returns it.
  326. **e** has an approximate value of 2.71828.
  327. ::
  328. a = exp(2) # approximately 7.39
  329. .. _class_@GDScript_floor:
  330. - :ref:`float<class_float>` **floor** **(** :ref:`float<class_float>` s **)**
  331. Rounds ``s`` to the closest smaller integer and returns it.
  332. ::
  333. # a is 2
  334. a = floor(2.99)
  335. # a is -3
  336. a = floor(-2.99)
  337. .. _class_@GDScript_fmod:
  338. - :ref:`float<class_float>` **fmod** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  339. Returns the floating-point remainder of ``x/y``.
  340. ::
  341. # remainder is 1.5
  342. var remainder = fmod(7, 5.5)
  343. .. _class_@GDScript_fposmod:
  344. - :ref:`float<class_float>` **fposmod** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  345. Returns the floating-point remainder of ``x/y`` that wraps equally in positive and negative.
  346. ::
  347. var i = -10;
  348. while i < 0:
  349. prints(i, fposmod(i, 10))
  350. i += 1
  351. Produces:
  352. ::
  353. -10 10
  354. -9 1
  355. -8 2
  356. -7 3
  357. -6 4
  358. -5 5
  359. -4 6
  360. -3 7
  361. -2 8
  362. -1 9
  363. .. _class_@GDScript_funcref:
  364. - :ref:`Object<class_object>` **funcref** **(** :ref:`Object<class_object>` instance, :ref:`String<class_string>` funcname **)**
  365. 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.
  366. ::
  367. func foo():
  368. return("bar")
  369. a = funcref(self, "foo")
  370. print(a.call_func()) # prints bar
  371. .. _class_@GDScript_hash:
  372. - :ref:`int<class_int>` **hash** **(** :ref:`Variant<class_variant>` var **)**
  373. Returns the integer hash of the variable passed.
  374. ::
  375. print(hash("a")) # prints 177670
  376. .. _class_@GDScript_inst2dict:
  377. - :ref:`Dictionary<class_dictionary>` **inst2dict** **(** :ref:`Object<class_object>` inst **)**
  378. Returns the passed instance converted to a dictionary (useful for serializing).
  379. ::
  380. var foo = "bar"
  381. func _ready():
  382. var d = inst2dict(self)
  383. print(d.keys())
  384. print(d.values())
  385. Prints out:
  386. ::
  387. [@subpath, @path, foo]
  388. [, res://test.gd, bar]
  389. .. _class_@GDScript_instance_from_id:
  390. - :ref:`Object<class_object>` **instance_from_id** **(** :ref:`int<class_int>` instance_id **)**
  391. Returns the Object that corresponds to ``instance_id``. All Objects have a unique instance ID.
  392. ::
  393. var foo = "bar"
  394. func _ready():
  395. var id = get_instance_id()
  396. var inst = instance_from_id(id)
  397. print(inst.foo) # prints bar
  398. .. _class_@GDScript_inverse_lerp:
  399. - :ref:`float<class_float>` **inverse_lerp** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)**
  400. Returns a normalized value considering the given range.
  401. ::
  402. inverse_lerp(3, 5, 4) # returns 0.5
  403. .. _class_@GDScript_is_inf:
  404. - :ref:`bool<class_bool>` **is_inf** **(** :ref:`float<class_float>` s **)**
  405. Returns True/False whether ``s`` is an infinity value (either positive infinity or negative infinity).
  406. .. _class_@GDScript_is_instance_valid:
  407. - :ref:`bool<class_bool>` **is_instance_valid** **(** :ref:`Object<class_object>` instance **)**
  408. .. _class_@GDScript_is_nan:
  409. - :ref:`bool<class_bool>` **is_nan** **(** :ref:`float<class_float>` s **)**
  410. Returns True/False whether ``s`` is a NaN (Not-A-Number) value.
  411. .. _class_@GDScript_len:
  412. - :ref:`int<class_int>` **len** **(** :ref:`Variant<class_variant>` var **)**
  413. 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.
  414. ::
  415. a = [1, 2, 3, 4]
  416. len(a) # returns 4
  417. .. _class_@GDScript_lerp:
  418. - :ref:`float<class_float>` **lerp** **(** :ref:`Variant<class_variant>` from, :ref:`Variant<class_variant>` to, :ref:`float<class_float>` weight **)**
  419. Linearly interpolates between two values by a normalized value.
  420. ::
  421. lerp(1, 3, 0.5) # returns 2
  422. .. _class_@GDScript_linear2db:
  423. - :ref:`float<class_float>` **linear2db** **(** :ref:`float<class_float>` nrg **)**
  424. Converts from linear energy to decibels (audio).
  425. .. _class_@GDScript_load:
  426. - :ref:`Object<class_object>` **load** **(** :ref:`String<class_string>` path **)**
  427. 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".
  428. ::
  429. # load a scene called main located in the root of the project directory
  430. var main = load("res://main.tscn")
  431. .. _class_@GDScript_log:
  432. - :ref:`float<class_float>` **log** **(** :ref:`float<class_float>` s **)**
  433. 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.
  434. ::
  435. log(10) # returns 2.302585
  436. .. _class_@GDScript_max:
  437. - :ref:`float<class_float>` **max** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
  438. Returns the maximum of two values.
  439. ::
  440. max(1,2) # returns 2
  441. max(-3.99, -4) # returns -3.99
  442. .. _class_@GDScript_min:
  443. - :ref:`float<class_float>` **min** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
  444. Returns the minimum of two values.
  445. ::
  446. min(1,2) # returns 1
  447. min(-3.99, -4) # returns -4
  448. .. _class_@GDScript_nearest_po2:
  449. - :ref:`int<class_int>` **nearest_po2** **(** :ref:`int<class_int>` value **)**
  450. Returns the nearest larger power of 2 for integer ``value``.
  451. ::
  452. nearest_po2(3) # returns 4
  453. nearest_po2(4) # returns 4
  454. nearest_po2(5) # returns 8
  455. .. _class_@GDScript_parse_json:
  456. - :ref:`Variant<class_variant>` **parse_json** **(** :ref:`String<class_string>` json **)**
  457. Parse JSON text to a Variant (use :ref:`typeof<class_@GDScript_typeof>` to check if it is what you expect).
  458. 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.
  459. 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:
  460. ::
  461. p = parse_json('["a", "b", "c"]')
  462. if typeof(p) == TYPE_ARRAY:
  463. print(p[0]) # prints a
  464. else:
  465. print("unexpected results")
  466. .. _class_@GDScript_polar2cartesian:
  467. - :ref:`Vector2<class_vector2>` **polar2cartesian** **(** :ref:`float<class_float>` r, :ref:`float<class_float>` th **)**
  468. 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).
  469. .. _class_@GDScript_pow:
  470. - :ref:`float<class_float>` **pow** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  471. Returns the result of ``x`` raised to the power of ``y``.
  472. ::
  473. pow(2,5) # returns 32
  474. .. _class_@GDScript_preload:
  475. - :ref:`Resource<class_resource>` **preload** **(** :ref:`String<class_string>` path **)**
  476. 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".
  477. ::
  478. # load a scene called main located in the root of the project directory
  479. var main = preload("res://main.tscn")
  480. .. _class_@GDScript_print:
  481. - void **print** **(** **)** vararg
  482. Converts one or more arguments to strings in the best way possible and prints them to the console.
  483. ::
  484. a = [1,2,3]
  485. print("a","b",a) # prints ab[1, 2, 3]
  486. .. _class_@GDScript_print_stack:
  487. - void **print_stack** **(** **)**
  488. Prints a stack track at code location, only works when running with debugger turned on.
  489. Output in the console would look something like this:
  490. ::
  491. Frame 0 - res://test.gd:16 in function '_process'
  492. .. _class_@GDScript_printerr:
  493. - void **printerr** **(** **)** vararg
  494. Prints one or more arguments to strings in the best way possible to standard error line.
  495. ::
  496. printerr("prints to stderr")
  497. .. _class_@GDScript_printraw:
  498. - void **printraw** **(** **)** vararg
  499. Prints one or more arguments to strings in the best way possible to console. No newline is added at the end.
  500. ::
  501. printraw("A")
  502. printraw("B")
  503. # prints AB
  504. .. _class_@GDScript_prints:
  505. - void **prints** **(** **)** vararg
  506. Prints one or more arguments to the console with a space between each argument.
  507. ::
  508. prints("A", "B", "C") # prints A B C
  509. .. _class_@GDScript_printt:
  510. - void **printt** **(** **)** vararg
  511. Prints one or more arguments to the console with a tab between each argument.
  512. ::
  513. printt("A", "B", "C") # prints A B C
  514. .. _class_@GDScript_rad2deg:
  515. - :ref:`float<class_float>` **rad2deg** **(** :ref:`float<class_float>` rad **)**
  516. Converts from radians to degrees.
  517. ::
  518. rad2deg(0.523599) # returns 30
  519. .. _class_@GDScript_rand_range:
  520. - :ref:`float<class_float>` **rand_range** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to **)**
  521. Random range, any floating point value between ``from`` and ``to``.
  522. ::
  523. prints(rand_range(0, 1), rand_range(0, 1)) # prints 0.135591 0.405263
  524. .. _class_@GDScript_rand_seed:
  525. - :ref:`Array<class_array>` **rand_seed** **(** :ref:`int<class_int>` seed **)**
  526. 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.
  527. .. _class_@GDScript_randf:
  528. - :ref:`float<class_float>` **randf** **(** **)**
  529. Returns a random floating point value between 0 and 1.
  530. ::
  531. randf() # returns 0.375671
  532. .. _class_@GDScript_randi:
  533. - :ref:`int<class_int>` **randi** **(** **)**
  534. 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).
  535. ::
  536. randi() % 20 # returns random number between 0 and 19
  537. randi() % 100 # returns random number between 0 and 99
  538. randi() % 100 + 1 # returns random number between 1 and 100
  539. .. _class_@GDScript_randomize:
  540. - void **randomize** **(** **)**
  541. Randomizes the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time.
  542. ::
  543. func _ready():
  544. randomize()
  545. .. _class_@GDScript_range:
  546. - :ref:`Array<class_array>` **range** **(** **)** vararg
  547. 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).
  548. ::
  549. for i in range(4):
  550. print(i)
  551. for i in range(2, 5):
  552. print(i)
  553. for i in range(0, 6, 2):
  554. print(i)
  555. Output:
  556. ::
  557. 0
  558. 1
  559. 2
  560. 3
  561. 2
  562. 3
  563. 4
  564. 0
  565. 2
  566. 4
  567. .. _class_@GDScript_range_lerp:
  568. - :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 **)**
  569. Maps a ``value`` from range ``[istart, istop]`` to ``[ostart, ostop]``.
  570. ::
  571. range_lerp(75, 0, 100, -1, 1) # returns 0.5
  572. .. _class_@GDScript_round:
  573. - :ref:`float<class_float>` **round** **(** :ref:`float<class_float>` s **)**
  574. Returns the integral value that is nearest to ``s``, with halfway cases rounded away from zero.
  575. ::
  576. round(2.6) # returns 3
  577. .. _class_@GDScript_seed:
  578. - void **seed** **(** :ref:`int<class_int>` seed **)**
  579. Sets seed for the random number generator.
  580. ::
  581. my_seed = "Godot Rocks"
  582. seed(my_seed.hash())
  583. .. _class_@GDScript_sign:
  584. - :ref:`float<class_float>` **sign** **(** :ref:`float<class_float>` s **)**
  585. Returns the sign of ``s``: -1 or 1. Returns 0 if ``s`` is 0.
  586. ::
  587. sign(-6) # returns -1
  588. sign(0) # returns 0
  589. sign(6) # returns 1
  590. .. _class_@GDScript_sin:
  591. - :ref:`float<class_float>` **sin** **(** :ref:`float<class_float>` s **)**
  592. Returns the sine of angle ``s`` in radians.
  593. ::
  594. sin(0.523599) # returns 0.5
  595. .. _class_@GDScript_sinh:
  596. - :ref:`float<class_float>` **sinh** **(** :ref:`float<class_float>` s **)**
  597. Returns the hyperbolic sine of ``s``.
  598. ::
  599. a = log(2.0) # returns 0.693147
  600. sinh(a) # returns 0.75
  601. .. _class_@GDScript_sqrt:
  602. - :ref:`float<class_float>` **sqrt** **(** :ref:`float<class_float>` s **)**
  603. Returns the square root of ``s``.
  604. ::
  605. sqrt(9) # returns 3
  606. .. _class_@GDScript_stepify:
  607. - :ref:`float<class_float>` **stepify** **(** :ref:`float<class_float>` s, :ref:`float<class_float>` step **)**
  608. Snaps float value ``s`` to a given ``step``.
  609. .. _class_@GDScript_str:
  610. - :ref:`String<class_string>` **str** **(** **)** vararg
  611. Converts one or more arguments to string in the best way possible.
  612. ::
  613. var a = [10, 20, 30]
  614. var b = str(a);
  615. len(a) # returns 3
  616. len(b) # returns 12
  617. .. _class_@GDScript_str2var:
  618. - :ref:`Variant<class_variant>` **str2var** **(** :ref:`String<class_string>` string **)**
  619. Converts a formatted string that was returned by :ref:`var2str<class_@GDScript_var2str>` to the original value.
  620. ::
  621. a = '{ "a": 1, "b": 2 }'
  622. b = str2var(a)
  623. print(b['a']) # prints 1
  624. .. _class_@GDScript_tan:
  625. - :ref:`float<class_float>` **tan** **(** :ref:`float<class_float>` s **)**
  626. Returns the tangent of angle ``s`` in radians.
  627. ::
  628. tan( deg2rad(45) ) # returns 1
  629. .. _class_@GDScript_tanh:
  630. - :ref:`float<class_float>` **tanh** **(** :ref:`float<class_float>` s **)**
  631. Returns the hyperbolic tangent of ``s``.
  632. ::
  633. a = log(2.0) # returns 0.693147
  634. tanh(a) # returns 0.6
  635. .. _class_@GDScript_to_json:
  636. - :ref:`String<class_string>` **to_json** **(** :ref:`Variant<class_variant>` var **)**
  637. Converts a Variant ``var`` to JSON text and return the result. Useful for serializing data to store or send over the network.
  638. ::
  639. a = { 'a': 1, 'b': 2 }
  640. b = to_json(a)
  641. print(b) # {"a":1, "b":2}
  642. .. _class_@GDScript_type_exists:
  643. - :ref:`bool<class_bool>` **type_exists** **(** :ref:`String<class_string>` type **)**
  644. Returns whether the given class exists in :ref:`ClassDB<class_classdb>`.
  645. ::
  646. type_exists("Sprite") # returns true
  647. type_exists("Variant") # returns false
  648. .. _class_@GDScript_typeof:
  649. - :ref:`int<class_int>` **typeof** **(** :ref:`Variant<class_variant>` what **)**
  650. Returns the internal type of the given Variant object, using the TYPE\_\* enum in :ref:`@GlobalScope<class_@globalscope>`.
  651. ::
  652. p = parse_json('["a", "b", "c"]')
  653. if typeof(p) == TYPE_ARRAY:
  654. print(p[0]) # prints a
  655. else:
  656. print("unexpected results")
  657. .. _class_@GDScript_validate_json:
  658. - :ref:`String<class_string>` **validate_json** **(** :ref:`String<class_string>` json **)**
  659. Checks that ``json`` is valid JSON data. Returns empty string if valid. Returns error message if not valid.
  660. ::
  661. j = to_json([1, 2, 3])
  662. v = validate_json(j)
  663. if not v:
  664. print("valid")
  665. else:
  666. prints("invalid", v)
  667. .. _class_@GDScript_var2bytes:
  668. - :ref:`PoolByteArray<class_poolbytearray>` **var2bytes** **(** :ref:`Variant<class_variant>` var **)**
  669. Encodes a variable value to a byte array.
  670. .. _class_@GDScript_var2str:
  671. - :ref:`String<class_string>` **var2str** **(** :ref:`Variant<class_variant>` var **)**
  672. Converts a Variant ``var`` to a formatted string that can later be parsed using :ref:`str2var<class_@GDScript_str2var>`.
  673. ::
  674. a = { 'a': 1, 'b': 2 }
  675. print(var2str(a))
  676. prints
  677. ::
  678. {
  679. "a": 1,
  680. "b": 2
  681. }
  682. .. _class_@GDScript_weakref:
  683. - :ref:`Object<class_object>` **weakref** **(** :ref:`Object<class_object>` obj **)**
  684. Returns a weak reference to an object.
  685. 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.
  686. .. _class_@GDScript_wrapf:
  687. - :ref:`float<class_float>` **wrapf** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)**
  688. Wraps float ``value`` between ``min`` and ``max``.
  689. Usable for creating loop-alike behavior or infinite surfaces.
  690. ::
  691. # a is 0.5
  692. a = wrapf(10.5, 0.0, 10.0)
  693. ::
  694. # a is 9.5
  695. a = wrapf(-0.5, 0.0, 10.0)
  696. ::
  697. # infinite loop between 0.0 and 0.99
  698. f = wrapf(f + 0.1, 0.0, 1.0)
  699. .. _class_@GDScript_wrapi:
  700. - :ref:`int<class_int>` **wrapi** **(** :ref:`int<class_int>` value, :ref:`int<class_int>` min, :ref:`int<class_int>` max **)**
  701. Wraps integer ``value`` between ``min`` and ``max``.
  702. Usable for creating loop-alike behavior or infinite surfaces.
  703. ::
  704. # a is 0
  705. a = wrapi(10, 0, 10)
  706. ::
  707. # a is 9
  708. a = wrapi(-1, 0, 10)
  709. ::
  710. # infinite loop between 0 and 9
  711. frame = wrapi(frame + 1, 0, 10)
  712. .. _class_@GDScript_yield:
  713. - :ref:`GDScriptFunctionState<class_gdscriptfunctionstate>` **yield** **(** :ref:`Object<class_object>` object=null, :ref:`String<class_string>` signal="" **)**
  714. 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.
  715. 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.