2
0

[email protected] 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/modules/gdscript/doc_classes/@GDScript.xml.
  6. .. _class_@GDScript:
  7. @GDScript
  8. =========
  9. Built-in GDScript functions.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. List of core built-in GDScript functions. Math functions and other utilities. Everything else is provided by objects. (Keywords: builtin, built in, global functions.)
  14. .. rst-class:: classref-reftable-group
  15. Methods
  16. -------
  17. .. table::
  18. :widths: auto
  19. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`Color<class_Color>` | :ref:`Color8<class_@GDScript_method_Color8>` **(** :ref:`int<class_int>` r8, :ref:`int<class_int>` g8, :ref:`int<class_int>` b8, :ref:`int<class_int>` a8=255 **)** |
  21. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`Color<class_Color>` | :ref:`ColorN<class_@GDScript_method_ColorN>` **(** :ref:`String<class_String>` name, :ref:`float<class_float>` alpha=1.0 **)** |
  23. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`float<class_float>` | :ref:`abs<class_@GDScript_method_abs>` **(** :ref:`float<class_float>` s **)** |
  25. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`float<class_float>` | :ref:`acos<class_@GDScript_method_acos>` **(** :ref:`float<class_float>` s **)** |
  27. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`float<class_float>` | :ref:`asin<class_@GDScript_method_asin>` **(** :ref:`float<class_float>` s **)** |
  29. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | void | :ref:`assert<class_@GDScript_method_assert>` **(** :ref:`bool<class_bool>` condition, :ref:`String<class_String>` message="" **)** |
  31. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`float<class_float>` | :ref:`atan<class_@GDScript_method_atan>` **(** :ref:`float<class_float>` s **)** |
  33. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`float<class_float>` | :ref:`atan2<class_@GDScript_method_atan2>` **(** :ref:`float<class_float>` y, :ref:`float<class_float>` x **)** |
  35. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Variant<class_Variant>` | :ref:`bytes2var<class_@GDScript_method_bytes2var>` **(** :ref:`PoolByteArray<class_PoolByteArray>` bytes, :ref:`bool<class_bool>` allow_objects=false **)** |
  37. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Vector2<class_Vector2>` | :ref:`cartesian2polar<class_@GDScript_method_cartesian2polar>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)** |
  39. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`float<class_float>` | :ref:`ceil<class_@GDScript_method_ceil>` **(** :ref:`float<class_float>` s **)** |
  41. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`String<class_String>` | :ref:`char<class_@GDScript_method_char>` **(** :ref:`int<class_int>` code **)** |
  43. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`float<class_float>` | :ref:`clamp<class_@GDScript_method_clamp>` **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)** |
  45. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Variant<class_Variant>` | :ref:`convert<class_@GDScript_method_convert>` **(** :ref:`Variant<class_Variant>` what, :ref:`int<class_int>` type **)** |
  47. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`float<class_float>` | :ref:`cos<class_@GDScript_method_cos>` **(** :ref:`float<class_float>` s **)** |
  49. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`float<class_float>` | :ref:`cosh<class_@GDScript_method_cosh>` **(** :ref:`float<class_float>` s **)** |
  51. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`float<class_float>` | :ref:`db2linear<class_@GDScript_method_db2linear>` **(** :ref:`float<class_float>` db **)** |
  53. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`int<class_int>` | :ref:`decimals<class_@GDScript_method_decimals>` **(** :ref:`float<class_float>` step **)** |
  55. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`float<class_float>` | :ref:`dectime<class_@GDScript_method_dectime>` **(** :ref:`float<class_float>` value, :ref:`float<class_float>` amount, :ref:`float<class_float>` step **)** |
  57. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`deep_equal<class_@GDScript_method_deep_equal>` **(** :ref:`Variant<class_Variant>` a, :ref:`Variant<class_Variant>` b **)** |
  59. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`float<class_float>` | :ref:`deg2rad<class_@GDScript_method_deg2rad>` **(** :ref:`float<class_float>` deg **)** |
  61. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Object<class_Object>` | :ref:`dict2inst<class_@GDScript_method_dict2inst>` **(** :ref:`Dictionary<class_Dictionary>` dict **)** |
  63. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`float<class_float>` | :ref:`ease<class_@GDScript_method_ease>` **(** :ref:`float<class_float>` s, :ref:`float<class_float>` curve **)** |
  65. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`float<class_float>` | :ref:`exp<class_@GDScript_method_exp>` **(** :ref:`float<class_float>` s **)** |
  67. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`float<class_float>` | :ref:`floor<class_@GDScript_method_floor>` **(** :ref:`float<class_float>` s **)** |
  69. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`float<class_float>` | :ref:`fmod<class_@GDScript_method_fmod>` **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)** |
  71. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`float<class_float>` | :ref:`fposmod<class_@GDScript_method_fposmod>` **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)** |
  73. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`FuncRef<class_FuncRef>` | :ref:`funcref<class_@GDScript_method_funcref>` **(** :ref:`Object<class_Object>` instance, :ref:`String<class_String>` funcname **)** |
  75. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Array<class_Array>` | :ref:`get_stack<class_@GDScript_method_get_stack>` **(** **)** |
  77. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`int<class_int>` | :ref:`hash<class_@GDScript_method_hash>` **(** :ref:`Variant<class_Variant>` var **)** |
  79. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`Dictionary<class_Dictionary>` | :ref:`inst2dict<class_@GDScript_method_inst2dict>` **(** :ref:`Object<class_Object>` inst **)** |
  81. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Object<class_Object>` | :ref:`instance_from_id<class_@GDScript_method_instance_from_id>` **(** :ref:`int<class_int>` instance_id **)** |
  83. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`float<class_float>` | :ref:`inverse_lerp<class_@GDScript_method_inverse_lerp>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)** |
  85. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_@GDScript_method_is_equal_approx>` **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)** |
  87. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`bool<class_bool>` | :ref:`is_inf<class_@GDScript_method_is_inf>` **(** :ref:`float<class_float>` s **)** |
  89. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`bool<class_bool>` | :ref:`is_instance_valid<class_@GDScript_method_is_instance_valid>` **(** :ref:`Object<class_Object>` instance **)** |
  91. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`bool<class_bool>` | :ref:`is_nan<class_@GDScript_method_is_nan>` **(** :ref:`float<class_float>` s **)** |
  93. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`bool<class_bool>` | :ref:`is_zero_approx<class_@GDScript_method_is_zero_approx>` **(** :ref:`float<class_float>` s **)** |
  95. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`int<class_int>` | :ref:`len<class_@GDScript_method_len>` **(** :ref:`Variant<class_Variant>` var **)** |
  97. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Variant<class_Variant>` | :ref:`lerp<class_@GDScript_method_lerp>` **(** :ref:`Variant<class_Variant>` from, :ref:`Variant<class_Variant>` to, :ref:`float<class_float>` weight **)** |
  99. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`float<class_float>` | :ref:`lerp_angle<class_@GDScript_method_lerp_angle>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)** |
  101. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`float<class_float>` | :ref:`linear2db<class_@GDScript_method_linear2db>` **(** :ref:`float<class_float>` nrg **)** |
  103. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`Resource<class_Resource>` | :ref:`load<class_@GDScript_method_load>` **(** :ref:`String<class_String>` path **)** |
  105. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`float<class_float>` | :ref:`log<class_@GDScript_method_log>` **(** :ref:`float<class_float>` s **)** |
  107. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`float<class_float>` | :ref:`max<class_@GDScript_method_max>` **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)** |
  109. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`float<class_float>` | :ref:`min<class_@GDScript_method_min>` **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)** |
  111. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`float<class_float>` | :ref:`move_toward<class_@GDScript_method_move_toward>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` delta **)** |
  113. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`int<class_int>` | :ref:`nearest_po2<class_@GDScript_method_nearest_po2>` **(** :ref:`int<class_int>` value **)** |
  115. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`int<class_int>` | :ref:`ord<class_@GDScript_method_ord>` **(** :ref:`String<class_String>` char **)** |
  117. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`Variant<class_Variant>` | :ref:`parse_json<class_@GDScript_method_parse_json>` **(** :ref:`String<class_String>` json **)** |
  119. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`Vector2<class_Vector2>` | :ref:`polar2cartesian<class_@GDScript_method_polar2cartesian>` **(** :ref:`float<class_float>` r, :ref:`float<class_float>` th **)** |
  121. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`int<class_int>` | :ref:`posmod<class_@GDScript_method_posmod>` **(** :ref:`int<class_int>` a, :ref:`int<class_int>` b **)** |
  123. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`float<class_float>` | :ref:`pow<class_@GDScript_method_pow>` **(** :ref:`float<class_float>` base, :ref:`float<class_float>` exp **)** |
  125. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | :ref:`Resource<class_Resource>` | :ref:`preload<class_@GDScript_method_preload>` **(** :ref:`String<class_String>` path **)** |
  127. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | void | :ref:`print<class_@GDScript_method_print>` **(** ... **)** |vararg| |
  129. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | void | :ref:`print_debug<class_@GDScript_method_print_debug>` **(** ... **)** |vararg| |
  131. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | void | :ref:`print_stack<class_@GDScript_method_print_stack>` **(** **)** |
  133. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | void | :ref:`printerr<class_@GDScript_method_printerr>` **(** ... **)** |vararg| |
  135. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | void | :ref:`printraw<class_@GDScript_method_printraw>` **(** ... **)** |vararg| |
  137. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | void | :ref:`prints<class_@GDScript_method_prints>` **(** ... **)** |vararg| |
  139. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. | void | :ref:`printt<class_@GDScript_method_printt>` **(** ... **)** |vararg| |
  141. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  142. | void | :ref:`push_error<class_@GDScript_method_push_error>` **(** :ref:`String<class_String>` message **)** |
  143. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  144. | void | :ref:`push_warning<class_@GDScript_method_push_warning>` **(** :ref:`String<class_String>` message **)** |
  145. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  146. | :ref:`float<class_float>` | :ref:`rad2deg<class_@GDScript_method_rad2deg>` **(** :ref:`float<class_float>` rad **)** |
  147. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  148. | :ref:`float<class_float>` | :ref:`rand_range<class_@GDScript_method_rand_range>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to **)** |
  149. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  150. | :ref:`Array<class_Array>` | :ref:`rand_seed<class_@GDScript_method_rand_seed>` **(** :ref:`int<class_int>` seed **)** |
  151. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  152. | :ref:`float<class_float>` | :ref:`randf<class_@GDScript_method_randf>` **(** **)** |
  153. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  154. | :ref:`int<class_int>` | :ref:`randi<class_@GDScript_method_randi>` **(** **)** |
  155. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  156. | void | :ref:`randomize<class_@GDScript_method_randomize>` **(** **)** |
  157. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  158. | :ref:`Array<class_Array>` | :ref:`range<class_@GDScript_method_range>` **(** ... **)** |vararg| |
  159. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  160. | :ref:`float<class_float>` | :ref:`range_lerp<class_@GDScript_method_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 **)** |
  161. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  162. | :ref:`float<class_float>` | :ref:`round<class_@GDScript_method_round>` **(** :ref:`float<class_float>` s **)** |
  163. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  164. | void | :ref:`seed<class_@GDScript_method_seed>` **(** :ref:`int<class_int>` seed **)** |
  165. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  166. | :ref:`float<class_float>` | :ref:`sign<class_@GDScript_method_sign>` **(** :ref:`float<class_float>` s **)** |
  167. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  168. | :ref:`float<class_float>` | :ref:`sin<class_@GDScript_method_sin>` **(** :ref:`float<class_float>` s **)** |
  169. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  170. | :ref:`float<class_float>` | :ref:`sinh<class_@GDScript_method_sinh>` **(** :ref:`float<class_float>` s **)** |
  171. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  172. | :ref:`float<class_float>` | :ref:`smoothstep<class_@GDScript_method_smoothstep>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` s **)** |
  173. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  174. | :ref:`float<class_float>` | :ref:`sqrt<class_@GDScript_method_sqrt>` **(** :ref:`float<class_float>` s **)** |
  175. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  176. | :ref:`int<class_int>` | :ref:`step_decimals<class_@GDScript_method_step_decimals>` **(** :ref:`float<class_float>` step **)** |
  177. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  178. | :ref:`float<class_float>` | :ref:`stepify<class_@GDScript_method_stepify>` **(** :ref:`float<class_float>` s, :ref:`float<class_float>` step **)** |
  179. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  180. | :ref:`String<class_String>` | :ref:`str<class_@GDScript_method_str>` **(** ... **)** |vararg| |
  181. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  182. | :ref:`Variant<class_Variant>` | :ref:`str2var<class_@GDScript_method_str2var>` **(** :ref:`String<class_String>` string **)** |
  183. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  184. | :ref:`float<class_float>` | :ref:`tan<class_@GDScript_method_tan>` **(** :ref:`float<class_float>` s **)** |
  185. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  186. | :ref:`float<class_float>` | :ref:`tanh<class_@GDScript_method_tanh>` **(** :ref:`float<class_float>` s **)** |
  187. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  188. | :ref:`String<class_String>` | :ref:`to_json<class_@GDScript_method_to_json>` **(** :ref:`Variant<class_Variant>` var **)** |
  189. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  190. | :ref:`bool<class_bool>` | :ref:`type_exists<class_@GDScript_method_type_exists>` **(** :ref:`String<class_String>` type **)** |
  191. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  192. | :ref:`int<class_int>` | :ref:`typeof<class_@GDScript_method_typeof>` **(** :ref:`Variant<class_Variant>` what **)** |
  193. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  194. | :ref:`String<class_String>` | :ref:`validate_json<class_@GDScript_method_validate_json>` **(** :ref:`String<class_String>` json **)** |
  195. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  196. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`var2bytes<class_@GDScript_method_var2bytes>` **(** :ref:`Variant<class_Variant>` var, :ref:`bool<class_bool>` full_objects=false **)** |
  197. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  198. | :ref:`String<class_String>` | :ref:`var2str<class_@GDScript_method_var2str>` **(** :ref:`Variant<class_Variant>` var **)** |
  199. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  200. | :ref:`WeakRef<class_WeakRef>` | :ref:`weakref<class_@GDScript_method_weakref>` **(** :ref:`Object<class_Object>` obj **)** |
  201. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  202. | :ref:`float<class_float>` | :ref:`wrapf<class_@GDScript_method_wrapf>` **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)** |
  203. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  204. | :ref:`int<class_int>` | :ref:`wrapi<class_@GDScript_method_wrapi>` **(** :ref:`int<class_int>` value, :ref:`int<class_int>` min, :ref:`int<class_int>` max **)** |
  205. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  206. | :ref:`GDScriptFunctionState<class_GDScriptFunctionState>` | :ref:`yield<class_@GDScript_method_yield>` **(** :ref:`Object<class_Object>` object=null, :ref:`String<class_String>` signal="" **)** |
  207. +-----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  208. .. rst-class:: classref-section-separator
  209. ----
  210. .. rst-class:: classref-descriptions-group
  211. Constants
  212. ---------
  213. .. _class_@GDScript_constant_PI:
  214. .. rst-class:: classref-constant
  215. **PI** = ``3.141593``
  216. Constant that represents how many times the diameter of a circle fits around its perimeter. This is equivalent to ``TAU / 2``.
  217. .. _class_@GDScript_constant_TAU:
  218. .. rst-class:: classref-constant
  219. **TAU** = ``6.283185``
  220. The circle constant, the circumference of the unit circle in radians. This is equivalent to ``PI * 2``, or 360 degrees in rotations.
  221. .. _class_@GDScript_constant_INF:
  222. .. rst-class:: classref-constant
  223. **INF** = ``inf``
  224. Positive floating-point infinity. This is the result of floating-point division when the divisor is ``0.0``. For negative infinity, use ``-INF``. Dividing by ``-0.0`` will result in negative infinity if the numerator is positive, so dividing by ``0.0`` is not the same as dividing by ``-0.0`` (despite ``0.0 == -0.0`` returning ``true``).
  225. \ **Note:** Numeric infinity is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer number by ``0`` will not result in :ref:`INF<class_@GDScript_constant_INF>` and will result in a run-time error instead.
  226. .. _class_@GDScript_constant_NAN:
  227. .. rst-class:: classref-constant
  228. **NAN** = ``nan``
  229. "Not a Number", an invalid floating-point value. :ref:`NAN<class_@GDScript_constant_NAN>` has special properties, including that it is not equal to itself (``NAN == NAN`` returns ``false``). It is output by some invalid operations, such as dividing floating-point ``0.0`` by ``0.0``.
  230. \ **Note:** "Not a Number" is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer ``0`` by ``0`` will not result in :ref:`NAN<class_@GDScript_constant_NAN>` and will result in a run-time error instead.
  231. .. rst-class:: classref-section-separator
  232. ----
  233. .. rst-class:: classref-descriptions-group
  234. Method Descriptions
  235. -------------------
  236. .. _class_@GDScript_method_Color8:
  237. .. rst-class:: classref-method
  238. :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 **)**
  239. Returns a color constructed from integer red, green, blue, and alpha channels. Each channel should have 8 bits of information ranging from 0 to 255.
  240. \ ``r8`` red channel
  241. \ ``g8`` green channel
  242. \ ``b8`` blue channel
  243. \ ``a8`` alpha channel
  244. ::
  245. red = Color8(255, 0, 0)
  246. .. rst-class:: classref-item-separator
  247. ----
  248. .. _class_@GDScript_method_ColorN:
  249. .. rst-class:: classref-method
  250. :ref:`Color<class_Color>` **ColorN** **(** :ref:`String<class_String>` name, :ref:`float<class_float>` alpha=1.0 **)**
  251. Returns a color according to the standardized ``name`` with ``alpha`` ranging from 0 to 1.
  252. ::
  253. red = ColorN("red", 1)
  254. Supported color names are the same as the constants defined in :ref:`Color<class_Color>`.
  255. .. rst-class:: classref-item-separator
  256. ----
  257. .. _class_@GDScript_method_abs:
  258. .. rst-class:: classref-method
  259. :ref:`float<class_float>` **abs** **(** :ref:`float<class_float>` s **)**
  260. Returns the absolute value of parameter ``s`` (i.e. positive value).
  261. ::
  262. a = abs(-1) # a is 1
  263. .. rst-class:: classref-item-separator
  264. ----
  265. .. _class_@GDScript_method_acos:
  266. .. rst-class:: classref-method
  267. :ref:`float<class_float>` **acos** **(** :ref:`float<class_float>` s **)**
  268. Returns the arc cosine of ``s`` in radians. Use to get the angle of cosine ``s``. ``s`` will be clamped between ``-1.0`` and ``1.0`` (inclusive), in order to prevent :ref:`acos<class_@GDScript_method_acos>` from returning :ref:`NAN<class_@GDScript_constant_NAN>`.
  269. ::
  270. # c is 0.523599 or 30 degrees if converted with rad2deg(s)
  271. c = acos(0.866025)
  272. .. rst-class:: classref-item-separator
  273. ----
  274. .. _class_@GDScript_method_asin:
  275. .. rst-class:: classref-method
  276. :ref:`float<class_float>` **asin** **(** :ref:`float<class_float>` s **)**
  277. Returns the arc sine of ``s`` in radians. Use to get the angle of sine ``s``. ``s`` will be clamped between ``-1.0`` and ``1.0`` (inclusive), in order to prevent :ref:`asin<class_@GDScript_method_asin>` from returning :ref:`NAN<class_@GDScript_constant_NAN>`.
  278. ::
  279. # s is 0.523599 or 30 degrees if converted with rad2deg(s)
  280. s = asin(0.5)
  281. .. rst-class:: classref-item-separator
  282. ----
  283. .. _class_@GDScript_method_assert:
  284. .. rst-class:: classref-method
  285. void **assert** **(** :ref:`bool<class_bool>` condition, :ref:`String<class_String>` message="" **)**
  286. Asserts that the ``condition`` is ``true``. If the ``condition`` is ``false``, an error is generated. When running from the editor, the running project will also be paused until you resume it. This can be used as a stronger form of :ref:`push_error<class_@GDScript_method_push_error>` for reporting errors to project developers or add-on users.
  287. \ **Note:** For performance reasons, the code inside :ref:`assert<class_@GDScript_method_assert>` is only executed in debug builds or when running the project from the editor. Don't include code that has side effects in an :ref:`assert<class_@GDScript_method_assert>` call. Otherwise, the project will behave differently when exported in release mode.
  288. The optional ``message`` argument, if given, is shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed.
  289. ::
  290. # Imagine we always want speed to be between 0 and 20.
  291. var speed = -10
  292. assert(speed < 20) # True, the program will continue
  293. assert(speed >= 0) # False, the program will stop
  294. assert(speed >= 0 and speed < 20) # You can also combine the two conditional statements in one check
  295. assert(speed < 20, "speed = %f, but the speed limit is 20" % speed) # Show a message with clarifying details
  296. .. rst-class:: classref-item-separator
  297. ----
  298. .. _class_@GDScript_method_atan:
  299. .. rst-class:: classref-method
  300. :ref:`float<class_float>` **atan** **(** :ref:`float<class_float>` s **)**
  301. 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``.
  302. The method cannot know in which quadrant the angle should fall. See :ref:`atan2<class_@GDScript_method_atan2>` if you have both ``y`` and ``x``.
  303. ::
  304. a = atan(0.5) # a is 0.463648
  305. .. rst-class:: classref-item-separator
  306. ----
  307. .. _class_@GDScript_method_atan2:
  308. .. rst-class:: classref-method
  309. :ref:`float<class_float>` **atan2** **(** :ref:`float<class_float>` y, :ref:`float<class_float>` x **)**
  310. 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.
  311. Important note: The Y coordinate comes first, by convention.
  312. ::
  313. a = atan2(0, -1) # a is 3.141593
  314. .. rst-class:: classref-item-separator
  315. ----
  316. .. _class_@GDScript_method_bytes2var:
  317. .. rst-class:: classref-method
  318. :ref:`Variant<class_Variant>` **bytes2var** **(** :ref:`PoolByteArray<class_PoolByteArray>` bytes, :ref:`bool<class_bool>` allow_objects=false **)**
  319. Decodes a byte array back to a value. When ``allow_objects`` is ``true`` decoding objects is allowed.
  320. \ **WARNING:** Deserialized object can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats (remote code execution).
  321. .. rst-class:: classref-item-separator
  322. ----
  323. .. _class_@GDScript_method_cartesian2polar:
  324. .. rst-class:: classref-method
  325. :ref:`Vector2<class_Vector2>` **cartesian2polar** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
  326. 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).
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_@GDScript_method_ceil:
  330. .. rst-class:: classref-method
  331. :ref:`float<class_float>` **ceil** **(** :ref:`float<class_float>` s **)**
  332. Rounds ``s`` upward (towards positive infinity), returning the smallest whole number that is not less than ``s``.
  333. ::
  334. a = ceil(1.45) # a is 2.0
  335. a = ceil(1.001) # a is 2.0
  336. See also :ref:`floor<class_@GDScript_method_floor>`, :ref:`round<class_@GDScript_method_round>`, :ref:`stepify<class_@GDScript_method_stepify>`, and :ref:`int<class_int>`.
  337. .. rst-class:: classref-item-separator
  338. ----
  339. .. _class_@GDScript_method_char:
  340. .. rst-class:: classref-method
  341. :ref:`String<class_String>` **char** **(** :ref:`int<class_int>` code **)**
  342. Returns a character as a String of the given Unicode code point (which is compatible with ASCII code).
  343. ::
  344. a = char(65) # a is "A"
  345. a = char(65 + 32) # a is "a"
  346. a = char(8364) # a is "€"
  347. This is the inverse of :ref:`ord<class_@GDScript_method_ord>`.
  348. .. rst-class:: classref-item-separator
  349. ----
  350. .. _class_@GDScript_method_clamp:
  351. .. rst-class:: classref-method
  352. :ref:`float<class_float>` **clamp** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)**
  353. Clamps ``value`` and returns a value not less than ``min`` and not more than ``max``.
  354. ::
  355. a = clamp(1000, 1, 20) # a is 20
  356. a = clamp(-10, 1, 20) # a is 1
  357. a = clamp(15, 1, 20) # a is 15
  358. .. rst-class:: classref-item-separator
  359. ----
  360. .. _class_@GDScript_method_convert:
  361. .. rst-class:: classref-method
  362. :ref:`Variant<class_Variant>` **convert** **(** :ref:`Variant<class_Variant>` what, :ref:`int<class_int>` type **)**
  363. Converts from a type to another in the best way possible. The ``type`` parameter uses the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` values.
  364. ::
  365. a = Vector2(1, 0)
  366. # Prints 1
  367. print(a.length())
  368. a = convert(a, TYPE_STRING)
  369. # Prints 6 as "(1, 0)" is 6 characters
  370. print(a.length())
  371. .. rst-class:: classref-item-separator
  372. ----
  373. .. _class_@GDScript_method_cos:
  374. .. rst-class:: classref-method
  375. :ref:`float<class_float>` **cos** **(** :ref:`float<class_float>` s **)**
  376. Returns the cosine of angle ``s`` in radians.
  377. ::
  378. a = cos(TAU) # a is 1.0
  379. a = cos(PI) # a is -1.0
  380. .. rst-class:: classref-item-separator
  381. ----
  382. .. _class_@GDScript_method_cosh:
  383. .. rst-class:: classref-method
  384. :ref:`float<class_float>` **cosh** **(** :ref:`float<class_float>` s **)**
  385. Returns the hyperbolic cosine of ``s`` in radians.
  386. ::
  387. print(cosh(1)) # Prints 1.543081
  388. .. rst-class:: classref-item-separator
  389. ----
  390. .. _class_@GDScript_method_db2linear:
  391. .. rst-class:: classref-method
  392. :ref:`float<class_float>` **db2linear** **(** :ref:`float<class_float>` db **)**
  393. Converts from decibels to linear energy (audio).
  394. .. rst-class:: classref-item-separator
  395. ----
  396. .. _class_@GDScript_method_decimals:
  397. .. rst-class:: classref-method
  398. :ref:`int<class_int>` **decimals** **(** :ref:`float<class_float>` step **)**
  399. Deprecated alias for :ref:`step_decimals<class_@GDScript_method_step_decimals>`.
  400. .. rst-class:: classref-item-separator
  401. ----
  402. .. _class_@GDScript_method_dectime:
  403. .. rst-class:: classref-method
  404. :ref:`float<class_float>` **dectime** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` amount, :ref:`float<class_float>` step **)**
  405. **Note:** ``dectime`` has been deprecated and will be removed in Godot 4.0, please use :ref:`move_toward<class_@GDScript_method_move_toward>` instead.
  406. Returns the result of ``value`` decreased by ``step`` \* ``amount``.
  407. ::
  408. a = dectime(60, 10, 0.1)) # a is 59.0
  409. .. rst-class:: classref-item-separator
  410. ----
  411. .. _class_@GDScript_method_deep_equal:
  412. .. rst-class:: classref-method
  413. :ref:`bool<class_bool>` **deep_equal** **(** :ref:`Variant<class_Variant>` a, :ref:`Variant<class_Variant>` b **)**
  414. Compares two values by checking their actual contents, recursing into any :ref:`Array<class_Array>` or :ref:`Dictionary<class_Dictionary>` up to its deepest level.
  415. This compares to ``==`` in a number of ways:
  416. - For ``null``, ``int``, ``float``, ``String``, ``Object`` and ``RID`` both ``deep_equal`` and ``==`` work the same.
  417. - For ``Dictionary``, ``==`` considers equality if, and only if, both variables point to the very same ``Dictionary``, with no recursion or awareness of the contents at all.
  418. - For ``Array``, ``==`` considers equality if, and only if, each item in the first ``Array`` is equal to its counterpart in the second ``Array``, as told by ``==`` itself. That implies that ``==`` recurses into ``Array``, but not into ``Dictionary``.
  419. In short, whenever a ``Dictionary`` is potentially involved, if you want a true content-aware comparison, you have to use ``deep_equal``.
  420. .. rst-class:: classref-item-separator
  421. ----
  422. .. _class_@GDScript_method_deg2rad:
  423. .. rst-class:: classref-method
  424. :ref:`float<class_float>` **deg2rad** **(** :ref:`float<class_float>` deg **)**
  425. Converts an angle expressed in degrees to radians.
  426. ::
  427. r = deg2rad(180) # r is 3.141593
  428. .. rst-class:: classref-item-separator
  429. ----
  430. .. _class_@GDScript_method_dict2inst:
  431. .. rst-class:: classref-method
  432. :ref:`Object<class_Object>` **dict2inst** **(** :ref:`Dictionary<class_Dictionary>` dict **)**
  433. Converts a dictionary (previously created with :ref:`inst2dict<class_@GDScript_method_inst2dict>`) back to an instance. Useful for deserializing.
  434. .. rst-class:: classref-item-separator
  435. ----
  436. .. _class_@GDScript_method_ease:
  437. .. rst-class:: classref-method
  438. :ref:`float<class_float>` **ease** **(** :ref:`float<class_float>` s, :ref:`float<class_float>` curve **)**
  439. Returns an "eased" value of ``x`` based on an easing function defined with ``curve``. This easing function is based on an exponent. The ``curve`` can be any floating-point number, with specific values leading to the following behaviors:
  440. ::
  441. - Lower than -1.0 (exclusive): Ease in-out
  442. - 1.0: Linear
  443. - Between -1.0 and 0.0 (exclusive): Ease out-in
  444. - 0.0: Constant
  445. - Between 0.0 to 1.0 (exclusive): Ease out
  446. - 1.0: Linear
  447. - Greater than 1.0 (exclusive): Ease in
  448. \ `ease() curve values cheatsheet <https://raw.githubusercontent.com/godotengine/godot-docs/3.6/img/ease_cheatsheet.png>`__\
  449. See also :ref:`smoothstep<class_@GDScript_method_smoothstep>`. If you need to perform more advanced transitions, use :ref:`Tween<class_Tween>` or :ref:`AnimationPlayer<class_AnimationPlayer>`.
  450. .. rst-class:: classref-item-separator
  451. ----
  452. .. _class_@GDScript_method_exp:
  453. .. rst-class:: classref-method
  454. :ref:`float<class_float>` **exp** **(** :ref:`float<class_float>` s **)**
  455. The natural exponential function. It raises the mathematical constant **e** to the power of ``s`` and returns it.
  456. \ **e** has an approximate value of 2.71828, and can be obtained with ``exp(1)``.
  457. For exponents to other bases use the method :ref:`pow<class_@GDScript_method_pow>`.
  458. ::
  459. a = exp(2) # Approximately 7.39
  460. .. rst-class:: classref-item-separator
  461. ----
  462. .. _class_@GDScript_method_floor:
  463. .. rst-class:: classref-method
  464. :ref:`float<class_float>` **floor** **(** :ref:`float<class_float>` s **)**
  465. Rounds ``s`` downward (towards negative infinity), returning the largest whole number that is not more than ``s``.
  466. ::
  467. a = floor(2.45) # a is 2.0
  468. a = floor(2.99) # a is 2.0
  469. a = floor(-2.99) # a is -3.0
  470. See also :ref:`ceil<class_@GDScript_method_ceil>`, :ref:`round<class_@GDScript_method_round>`, :ref:`stepify<class_@GDScript_method_stepify>`, and :ref:`int<class_int>`.
  471. \ **Note:** This method returns a float. If you need an integer and ``s`` is a non-negative number, you can use ``int(s)`` directly.
  472. .. rst-class:: classref-item-separator
  473. ----
  474. .. _class_@GDScript_method_fmod:
  475. .. rst-class:: classref-method
  476. :ref:`float<class_float>` **fmod** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
  477. Returns the floating-point remainder of ``a/b``, keeping the sign of ``a``.
  478. ::
  479. r = fmod(7, 5.5) # r is 1.5
  480. For the integer remainder operation, use the % operator.
  481. .. rst-class:: classref-item-separator
  482. ----
  483. .. _class_@GDScript_method_fposmod:
  484. .. rst-class:: classref-method
  485. :ref:`float<class_float>` **fposmod** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
  486. Returns the floating-point modulus of ``a/b`` that wraps equally in positive and negative.
  487. ::
  488. for i in 7:
  489. var x = 0.5 * i - 1.5
  490. print("%4.1f %4.1f %4.1f" % [x, fmod(x, 1.5), fposmod(x, 1.5)])
  491. Produces:
  492. ::
  493. -1.5 -0.0 0.0
  494. -1.0 -1.0 0.5
  495. -0.5 -0.5 1.0
  496. 0.0 0.0 0.0
  497. 0.5 0.5 0.5
  498. 1.0 1.0 1.0
  499. 1.5 0.0 0.0
  500. .. rst-class:: classref-item-separator
  501. ----
  502. .. _class_@GDScript_method_funcref:
  503. .. rst-class:: classref-method
  504. :ref:`FuncRef<class_FuncRef>` **funcref** **(** :ref:`Object<class_Object>` instance, :ref:`String<class_String>` funcname **)**
  505. 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.
  506. ::
  507. func foo():
  508. return("bar")
  509. a = funcref(self, "foo")
  510. print(a.call_func()) # Prints bar
  511. .. rst-class:: classref-item-separator
  512. ----
  513. .. _class_@GDScript_method_get_stack:
  514. .. rst-class:: classref-method
  515. :ref:`Array<class_Array>` **get_stack** **(** **)**
  516. Returns an array of dictionaries representing the current call stack. See also :ref:`print_stack<class_@GDScript_method_print_stack>`.
  517. ::
  518. func _ready():
  519. foo()
  520. func foo():
  521. bar()
  522. func bar():
  523. print(get_stack())
  524. would print
  525. ::
  526. [{function:bar, line:12, source:res://script.gd}, {function:foo, line:9, source:res://script.gd}, {function:_ready, line:6, source:res://script.gd}]
  527. \ **Note:** :ref:`get_stack<class_@GDScript_method_get_stack>` only works if the running instance is connected to a debugging server (i.e. an editor instance). :ref:`get_stack<class_@GDScript_method_get_stack>` will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
  528. .. rst-class:: classref-item-separator
  529. ----
  530. .. _class_@GDScript_method_hash:
  531. .. rst-class:: classref-method
  532. :ref:`int<class_int>` **hash** **(** :ref:`Variant<class_Variant>` var **)**
  533. Returns the integer hash of the variable passed.
  534. ::
  535. print(hash("a")) # Prints 177670
  536. .. rst-class:: classref-item-separator
  537. ----
  538. .. _class_@GDScript_method_inst2dict:
  539. .. rst-class:: classref-method
  540. :ref:`Dictionary<class_Dictionary>` **inst2dict** **(** :ref:`Object<class_Object>` inst **)**
  541. Returns the passed instance converted to a dictionary (useful for serializing).
  542. ::
  543. var foo = "bar"
  544. func _ready():
  545. var d = inst2dict(self)
  546. print(d.keys())
  547. print(d.values())
  548. Prints out:
  549. ::
  550. [@subpath, @path, foo]
  551. [, res://test.gd, bar]
  552. .. rst-class:: classref-item-separator
  553. ----
  554. .. _class_@GDScript_method_instance_from_id:
  555. .. rst-class:: classref-method
  556. :ref:`Object<class_Object>` **instance_from_id** **(** :ref:`int<class_int>` instance_id **)**
  557. Returns the Object that corresponds to ``instance_id``. All Objects have a unique instance ID.
  558. ::
  559. var foo = "bar"
  560. func _ready():
  561. var id = get_instance_id()
  562. var inst = instance_from_id(id)
  563. print(inst.foo) # Prints bar
  564. .. rst-class:: classref-item-separator
  565. ----
  566. .. _class_@GDScript_method_inverse_lerp:
  567. .. rst-class:: classref-method
  568. :ref:`float<class_float>` **inverse_lerp** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)**
  569. Returns an interpolation or extrapolation factor considering the range specified in ``from`` and ``to``, and the interpolated value specified in ``weight``. The returned value will be between ``0.0`` and ``1.0`` if ``weight`` is between ``from`` and ``to`` (inclusive). If ``weight`` is located outside this range, then an extrapolation factor will be returned (return value lower than ``0.0`` or greater than ``1.0``). Use :ref:`clamp<class_@GDScript_method_clamp>` on the result of :ref:`inverse_lerp<class_@GDScript_method_inverse_lerp>` if this is not desired.
  570. ::
  571. # The interpolation ratio in the `lerp()` call below is 0.75.
  572. var middle = lerp(20, 30, 0.75)
  573. # `middle` is now 27.5.
  574. # Now, we pretend to have forgotten the original ratio and want to get it back.
  575. var ratio = inverse_lerp(20, 30, 27.5)
  576. # `ratio` is now 0.75.
  577. See also :ref:`lerp<class_@GDScript_method_lerp>` which performs the reverse of this operation, and :ref:`range_lerp<class_@GDScript_method_range_lerp>` to map a continuous series of values to another.
  578. .. rst-class:: classref-item-separator
  579. ----
  580. .. _class_@GDScript_method_is_equal_approx:
  581. .. rst-class:: classref-method
  582. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
  583. Returns ``true`` if ``a`` and ``b`` are approximately equal to each other.
  584. Here, approximately equal means that ``a`` and ``b`` are within a small internal epsilon of each other, which scales with the magnitude of the numbers.
  585. Infinity values of the same sign are considered equal.
  586. .. rst-class:: classref-item-separator
  587. ----
  588. .. _class_@GDScript_method_is_inf:
  589. .. rst-class:: classref-method
  590. :ref:`bool<class_bool>` **is_inf** **(** :ref:`float<class_float>` s **)**
  591. Returns whether ``s`` is an infinity value (either positive infinity or negative infinity).
  592. .. rst-class:: classref-item-separator
  593. ----
  594. .. _class_@GDScript_method_is_instance_valid:
  595. .. rst-class:: classref-method
  596. :ref:`bool<class_bool>` **is_instance_valid** **(** :ref:`Object<class_Object>` instance **)**
  597. Returns whether ``instance`` is a valid object (e.g. has not been deleted from memory).
  598. .. rst-class:: classref-item-separator
  599. ----
  600. .. _class_@GDScript_method_is_nan:
  601. .. rst-class:: classref-method
  602. :ref:`bool<class_bool>` **is_nan** **(** :ref:`float<class_float>` s **)**
  603. Returns whether ``s`` is a NaN ("Not a Number" or invalid) value.
  604. .. rst-class:: classref-item-separator
  605. ----
  606. .. _class_@GDScript_method_is_zero_approx:
  607. .. rst-class:: classref-method
  608. :ref:`bool<class_bool>` **is_zero_approx** **(** :ref:`float<class_float>` s **)**
  609. Returns ``true`` if ``s`` is zero or almost zero.
  610. This method is faster than using :ref:`is_equal_approx<class_@GDScript_method_is_equal_approx>` with one value as zero.
  611. .. rst-class:: classref-item-separator
  612. ----
  613. .. _class_@GDScript_method_len:
  614. .. rst-class:: classref-method
  615. :ref:`int<class_int>` **len** **(** :ref:`Variant<class_Variant>` var **)**
  616. Returns length of Variant ``var``. Length is the character count of String, element count of Array, size of Dictionary, etc.
  617. \ **Note:** Generates a fatal error if Variant can not provide a length.
  618. ::
  619. a = [1, 2, 3, 4]
  620. len(a) # Returns 4
  621. .. rst-class:: classref-item-separator
  622. ----
  623. .. _class_@GDScript_method_lerp:
  624. .. rst-class:: classref-method
  625. :ref:`Variant<class_Variant>` **lerp** **(** :ref:`Variant<class_Variant>` from, :ref:`Variant<class_Variant>` to, :ref:`float<class_float>` weight **)**
  626. Linearly interpolates between two values by the factor defined in ``weight``. To perform interpolation, ``weight`` should be between ``0.0`` and ``1.0`` (inclusive). However, values outside this range are allowed and can be used to perform *extrapolation*. Use :ref:`clamp<class_@GDScript_method_clamp>` on the result of :ref:`lerp<class_@GDScript_method_lerp>` if this is not desired.
  627. If the ``from`` and ``to`` arguments are of type :ref:`int<class_int>` or :ref:`float<class_float>`, the return value is a :ref:`float<class_float>`.
  628. If both are of the same vector type (:ref:`Vector2<class_Vector2>`, :ref:`Vector3<class_Vector3>` or :ref:`Color<class_Color>`), the return value will be of the same type (``lerp`` then calls the vector type's ``linear_interpolate`` method).
  629. ::
  630. lerp(0, 4, 0.75) # Returns 3.0
  631. lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # Returns Vector2(2, 3.5)
  632. See also :ref:`inverse_lerp<class_@GDScript_method_inverse_lerp>` which performs the reverse of this operation. To perform eased interpolation with :ref:`lerp<class_@GDScript_method_lerp>`, combine it with :ref:`ease<class_@GDScript_method_ease>` or :ref:`smoothstep<class_@GDScript_method_smoothstep>`. See also :ref:`range_lerp<class_@GDScript_method_range_lerp>` to map a continuous series of values to another.
  633. .. rst-class:: classref-item-separator
  634. ----
  635. .. _class_@GDScript_method_lerp_angle:
  636. .. rst-class:: classref-method
  637. :ref:`float<class_float>` **lerp_angle** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)**
  638. Linearly interpolates between two angles (in radians) by a normalized value.
  639. Similar to :ref:`lerp<class_@GDScript_method_lerp>`, but interpolates correctly when the angles wrap around :ref:`TAU<class_@GDScript_constant_TAU>`. To perform eased interpolation with :ref:`lerp_angle<class_@GDScript_method_lerp_angle>`, combine it with :ref:`ease<class_@GDScript_method_ease>` or :ref:`smoothstep<class_@GDScript_method_smoothstep>`.
  640. ::
  641. extends Sprite
  642. var elapsed = 0.0
  643. func _process(delta):
  644. var min_angle = deg2rad(0.0)
  645. var max_angle = deg2rad(90.0)
  646. rotation = lerp_angle(min_angle, max_angle, elapsed)
  647. elapsed += delta
  648. \ **Note:** This method lerps through the shortest path between ``from`` and ``to``. However, when these two angles are approximately ``PI + k * TAU`` apart for any integer ``k``, it's not obvious which way they lerp due to floating-point precision errors. For example, ``lerp_angle(0, PI, weight)`` lerps counter-clockwise, while ``lerp_angle(0, PI + 5 * TAU, weight)`` lerps clockwise.
  649. .. rst-class:: classref-item-separator
  650. ----
  651. .. _class_@GDScript_method_linear2db:
  652. .. rst-class:: classref-method
  653. :ref:`float<class_float>` **linear2db** **(** :ref:`float<class_float>` nrg **)**
  654. Converts from linear energy to decibels (audio). This can be used to implement volume sliders that behave as expected (since volume isn't linear). Example:
  655. ::
  656. # "Slider" refers to a node that inherits Range such as HSlider or VSlider.
  657. # Its range must be configured to go from 0 to 1.
  658. # Change the bus name if you'd like to change the volume of a specific bus only.
  659. AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), linear2db($Slider.value))
  660. .. rst-class:: classref-item-separator
  661. ----
  662. .. _class_@GDScript_method_load:
  663. .. rst-class:: classref-method
  664. :ref:`Resource<class_Resource>` **load** **(** :ref:`String<class_String>` path **)**
  665. Loads a resource from the filesystem located at ``path``. The resource is loaded on the method call (unless it's referenced already elsewhere, e.g. in another script or in the scene), which might cause slight delay, especially when loading scenes. To avoid unnecessary delays when loading something multiple times, either store the resource in a variable or use :ref:`preload<class_@GDScript_method_preload>`.
  666. \ **Note:** Resource paths can be obtained by right-clicking on a resource in the FileSystem dock and choosing "Copy Path" or by dragging the file from the FileSystem dock into the script.
  667. ::
  668. # Load a scene called main located in the root of the project directory and cache it in a variable.
  669. var main = load("res://main.tscn") # main will contain a PackedScene resource.
  670. \ **Important:** The path must be absolute, a local path will just return ``null``.
  671. This method is a simplified version of :ref:`ResourceLoader.load<class_ResourceLoader_method_load>`, which can be used for more advanced scenarios.
  672. .. rst-class:: classref-item-separator
  673. ----
  674. .. _class_@GDScript_method_log:
  675. .. rst-class:: classref-method
  676. :ref:`float<class_float>` **log** **(** :ref:`float<class_float>` s **)**
  677. Returns the `natural logarithm <https://en.wikipedia.org/wiki/Natural_logarithm>`__ of ``s`` (base `[i]e[/i] <https://en.wikipedia.org/wiki/E_(mathematical_constant)>`__, with *e* being approximately 2.71828). This is the amount of time needed to reach a certain level of continuous growth.
  678. \ **Note:** This is not the same as the "log" function on most calculators, which uses a base 10 logarithm. To use base 10 logarithm, use ``log(x) / log(10)``.
  679. ::
  680. log(10) # Returns 2.302585
  681. \ **Note:** The logarithm of ``0`` returns ``-inf``, while negative values return ``-nan``.
  682. .. rst-class:: classref-item-separator
  683. ----
  684. .. _class_@GDScript_method_max:
  685. .. rst-class:: classref-method
  686. :ref:`float<class_float>` **max** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
  687. Returns the maximum of two values.
  688. ::
  689. max(1, 2) # Returns 2
  690. max(-3.99, -4) # Returns -3.99
  691. .. rst-class:: classref-item-separator
  692. ----
  693. .. _class_@GDScript_method_min:
  694. .. rst-class:: classref-method
  695. :ref:`float<class_float>` **min** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
  696. Returns the minimum of two values.
  697. ::
  698. min(1, 2) # Returns 1
  699. min(-3.99, -4) # Returns -4
  700. .. rst-class:: classref-item-separator
  701. ----
  702. .. _class_@GDScript_method_move_toward:
  703. .. rst-class:: classref-method
  704. :ref:`float<class_float>` **move_toward** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` delta **)**
  705. Moves ``from`` toward ``to`` by the ``delta`` value.
  706. Use a negative ``delta`` value to move away.
  707. ::
  708. move_toward(5, 10, 4) # Returns 9
  709. move_toward(10, 5, 4) # Returns 6
  710. move_toward(10, 5, -1.5) # Returns 11.5
  711. .. rst-class:: classref-item-separator
  712. ----
  713. .. _class_@GDScript_method_nearest_po2:
  714. .. rst-class:: classref-method
  715. :ref:`int<class_int>` **nearest_po2** **(** :ref:`int<class_int>` value **)**
  716. Returns the nearest equal or larger power of 2 for integer ``value``.
  717. In other words, returns the smallest value ``a`` where ``a = pow(2, n)`` such that ``value <= a`` for some non-negative integer ``n``.
  718. ::
  719. nearest_po2(3) # Returns 4
  720. nearest_po2(4) # Returns 4
  721. nearest_po2(5) # Returns 8
  722. nearest_po2(0) # Returns 0 (this may not be what you expect)
  723. nearest_po2(-1) # Returns 0 (this may not be what you expect)
  724. \ **WARNING:** Due to the way it is implemented, this function returns ``0`` rather than ``1`` for non-positive values of ``value`` (in reality, 1 is the smallest integer power of 2).
  725. .. rst-class:: classref-item-separator
  726. ----
  727. .. _class_@GDScript_method_ord:
  728. .. rst-class:: classref-method
  729. :ref:`int<class_int>` **ord** **(** :ref:`String<class_String>` char **)**
  730. Returns an integer representing the Unicode code point of the given Unicode character ``char``.
  731. ::
  732. a = ord("A") # a is 65
  733. a = ord("a") # a is 97
  734. a = ord("€") # a is 8364
  735. This is the inverse of :ref:`char<class_@GDScript_method_char>`.
  736. .. rst-class:: classref-item-separator
  737. ----
  738. .. _class_@GDScript_method_parse_json:
  739. .. rst-class:: classref-method
  740. :ref:`Variant<class_Variant>` **parse_json** **(** :ref:`String<class_String>` json **)**
  741. Parse JSON text to a Variant. (Use :ref:`typeof<class_@GDScript_method_typeof>` to check if the Variant's type is what you expect.)
  742. \ **Note:** 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.
  743. \ **Note:** 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:
  744. ::
  745. var p = JSON.parse('["hello", "world", "!"]')
  746. if typeof(p.result) == TYPE_ARRAY:
  747. print(p.result[0]) # Prints "hello"
  748. else:
  749. push_error("Unexpected results.")
  750. See also :ref:`JSON<class_JSON>` for an alternative way to parse JSON text.
  751. .. rst-class:: classref-item-separator
  752. ----
  753. .. _class_@GDScript_method_polar2cartesian:
  754. .. rst-class:: classref-method
  755. :ref:`Vector2<class_Vector2>` **polar2cartesian** **(** :ref:`float<class_float>` r, :ref:`float<class_float>` th **)**
  756. 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).
  757. .. rst-class:: classref-item-separator
  758. ----
  759. .. _class_@GDScript_method_posmod:
  760. .. rst-class:: classref-method
  761. :ref:`int<class_int>` **posmod** **(** :ref:`int<class_int>` a, :ref:`int<class_int>` b **)**
  762. Returns the integer modulus of ``a/b`` that wraps equally in positive and negative.
  763. ::
  764. for i in range(-3, 4):
  765. print("%2d %2d %2d" % [i, i % 3, posmod(i, 3)])
  766. Produces:
  767. ::
  768. -3 0 0
  769. -2 -2 1
  770. -1 -1 2
  771. 0 0 0
  772. 1 1 1
  773. 2 2 2
  774. 3 0 0
  775. .. rst-class:: classref-item-separator
  776. ----
  777. .. _class_@GDScript_method_pow:
  778. .. rst-class:: classref-method
  779. :ref:`float<class_float>` **pow** **(** :ref:`float<class_float>` base, :ref:`float<class_float>` exp **)**
  780. Returns the result of ``base`` raised to the power of ``exp``.
  781. ::
  782. pow(2, 5) # Returns 32.0
  783. .. rst-class:: classref-item-separator
  784. ----
  785. .. _class_@GDScript_method_preload:
  786. .. rst-class:: classref-method
  787. :ref:`Resource<class_Resource>` **preload** **(** :ref:`String<class_String>` path **)**
  788. Returns a :ref:`Resource<class_Resource>` from the filesystem located at ``path``. The resource is loaded during script parsing, i.e. is loaded with the script and :ref:`preload<class_@GDScript_method_preload>` effectively acts as a reference to that resource. Note that the method requires a constant path. If you want to load a resource from a dynamic/variable path, use :ref:`load<class_@GDScript_method_load>`.
  789. \ **Note:** Resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path" or by dragging the file from the FileSystem dock into the script.
  790. ::
  791. # Instance a scene.
  792. var diamond = preload("res://diamond.tscn").instance()
  793. .. rst-class:: classref-item-separator
  794. ----
  795. .. _class_@GDScript_method_print:
  796. .. rst-class:: classref-method
  797. void **print** **(** ... **)** |vararg|
  798. Converts one or more arguments of any type to string in the best way possible and prints them to the console.
  799. ::
  800. a = [1, 2, 3]
  801. print("a", "=", a) # Prints a=[1, 2, 3]
  802. \ **Note:** Consider using :ref:`push_error<class_@GDScript_method_push_error>` and :ref:`push_warning<class_@GDScript_method_push_warning>` to print error and warning messages instead of :ref:`print<class_@GDScript_method_print>`. This distinguishes them from print messages used for debugging purposes, while also displaying a stack trace when an error or warning is printed.
  803. .. rst-class:: classref-item-separator
  804. ----
  805. .. _class_@GDScript_method_print_debug:
  806. .. rst-class:: classref-method
  807. void **print_debug** **(** ... **)** |vararg|
  808. Like :ref:`print<class_@GDScript_method_print>`, but includes the current stack frame when running with the debugger turned on.
  809. Output in the console would look something like this:
  810. ::
  811. Test print
  812. At: res://test.gd:15:_process()
  813. .. rst-class:: classref-item-separator
  814. ----
  815. .. _class_@GDScript_method_print_stack:
  816. .. rst-class:: classref-method
  817. void **print_stack** **(** **)**
  818. Prints a stack trace at the current code location. See also :ref:`get_stack<class_@GDScript_method_get_stack>`.
  819. Output in the console would look something like this:
  820. ::
  821. Frame 0 - res://test.gd:16 in function '_process'
  822. \ **Note:** :ref:`print_stack<class_@GDScript_method_print_stack>` only works if the running instance is connected to a debugging server (i.e. an editor instance). :ref:`print_stack<class_@GDScript_method_print_stack>` will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
  823. .. rst-class:: classref-item-separator
  824. ----
  825. .. _class_@GDScript_method_printerr:
  826. .. rst-class:: classref-method
  827. void **printerr** **(** ... **)** |vararg|
  828. Prints one or more arguments to strings in the best way possible to standard error line.
  829. ::
  830. printerr("prints to stderr")
  831. .. rst-class:: classref-item-separator
  832. ----
  833. .. _class_@GDScript_method_printraw:
  834. .. rst-class:: classref-method
  835. void **printraw** **(** ... **)** |vararg|
  836. Prints one or more arguments to strings in the best way possible to console. No newline is added at the end.
  837. ::
  838. printraw("A")
  839. printraw("B")
  840. # Prints AB
  841. \ **Note:** Due to limitations with Godot's built-in console, this only prints to the terminal. If you need to print in the editor, use another method, such as :ref:`print<class_@GDScript_method_print>`.
  842. .. rst-class:: classref-item-separator
  843. ----
  844. .. _class_@GDScript_method_prints:
  845. .. rst-class:: classref-method
  846. void **prints** **(** ... **)** |vararg|
  847. Prints one or more arguments to the console with a space between each argument.
  848. ::
  849. prints("A", "B", "C") # Prints A B C
  850. .. rst-class:: classref-item-separator
  851. ----
  852. .. _class_@GDScript_method_printt:
  853. .. rst-class:: classref-method
  854. void **printt** **(** ... **)** |vararg|
  855. Prints one or more arguments to the console with a tab between each argument.
  856. ::
  857. printt("A", "B", "C") # Prints A B C
  858. .. rst-class:: classref-item-separator
  859. ----
  860. .. _class_@GDScript_method_push_error:
  861. .. rst-class:: classref-method
  862. void **push_error** **(** :ref:`String<class_String>` message **)**
  863. Pushes an error message to Godot's built-in debugger and to the OS terminal.
  864. ::
  865. push_error("test error") # Prints "test error" to debugger and terminal as error call
  866. \ **Note:** Errors printed this way will not pause project execution. To print an error message and pause project execution in debug builds, use ``assert(false, "test error")`` instead.
  867. .. rst-class:: classref-item-separator
  868. ----
  869. .. _class_@GDScript_method_push_warning:
  870. .. rst-class:: classref-method
  871. void **push_warning** **(** :ref:`String<class_String>` message **)**
  872. Pushes a warning message to Godot's built-in debugger and to the OS terminal.
  873. ::
  874. push_warning("test warning") # Prints "test warning" to debugger and terminal as warning call
  875. .. rst-class:: classref-item-separator
  876. ----
  877. .. _class_@GDScript_method_rad2deg:
  878. .. rst-class:: classref-method
  879. :ref:`float<class_float>` **rad2deg** **(** :ref:`float<class_float>` rad **)**
  880. Converts an angle expressed in radians to degrees.
  881. ::
  882. rad2deg(0.523599) # Returns 30.0
  883. .. rst-class:: classref-item-separator
  884. ----
  885. .. _class_@GDScript_method_rand_range:
  886. .. rst-class:: classref-method
  887. :ref:`float<class_float>` **rand_range** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to **)**
  888. Returns a random floating point value between ``from`` and ``to`` (both endpoints inclusive).
  889. ::
  890. prints(rand_range(0, 1), rand_range(0, 1)) # Prints e.g. 0.135591 0.405263
  891. \ **Note:** This is equivalent to ``randf() * (to - from) + from``.
  892. .. rst-class:: classref-item-separator
  893. ----
  894. .. _class_@GDScript_method_rand_seed:
  895. .. rst-class:: classref-method
  896. :ref:`Array<class_Array>` **rand_seed** **(** :ref:`int<class_int>` seed **)**
  897. 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.
  898. .. rst-class:: classref-item-separator
  899. ----
  900. .. _class_@GDScript_method_randf:
  901. .. rst-class:: classref-method
  902. :ref:`float<class_float>` **randf** **(** **)**
  903. Returns a random floating point value on the interval ``[0, 1]``.
  904. ::
  905. randf() # Returns e.g. 0.375671
  906. .. rst-class:: classref-item-separator
  907. ----
  908. .. _class_@GDScript_method_randi:
  909. .. rst-class:: classref-method
  910. :ref:`int<class_int>` **randi** **(** **)**
  911. Returns a random unsigned 32-bit integer. Use remainder to obtain a random value in the interval ``[0, N - 1]`` (where N is smaller than 2^32).
  912. ::
  913. randi() # Returns random integer between 0 and 2^32 - 1
  914. randi() % 20 # Returns random integer between 0 and 19
  915. randi() % 100 # Returns random integer between 0 and 99
  916. randi() % 100 + 1 # Returns random integer between 1 and 100
  917. .. rst-class:: classref-item-separator
  918. ----
  919. .. _class_@GDScript_method_randomize:
  920. .. rst-class:: classref-method
  921. void **randomize** **(** **)**
  922. Randomizes the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time.
  923. ::
  924. func _ready():
  925. randomize()
  926. .. rst-class:: classref-item-separator
  927. ----
  928. .. _class_@GDScript_method_range:
  929. .. rst-class:: classref-method
  930. :ref:`Array<class_Array>` **range** **(** ... **)** |vararg|
  931. Returns an array with the given range. :ref:`range<class_@GDScript_method_range>` can be called in three ways:
  932. \ ``range(n: int)``: Starts from 0, increases by steps of 1, and stops *before* ``n``. The argument ``n`` is **exclusive**.
  933. \ ``range(b: int, n: int)``: Starts from ``b``, increases by steps of 1, and stops *before* ``n``. The arguments ``b`` and ``n`` are **inclusive** and **exclusive**, respectively.
  934. \ ``range(b: int, n: int, s: int)``: Starts from ``b``, increases/decreases by steps of ``s``, and stops *before* ``n``. The arguments ``b`` and ``n`` are **inclusive** and **exclusive**, respectively. The argument ``s`` **can** be negative, but not ``0``. If ``s`` is ``0``, an error message is printed.
  935. \ :ref:`range<class_@GDScript_method_range>` converts all arguments to :ref:`int<class_int>` before processing.
  936. \ **Note:** Returns an empty array if no value meets the value constraint (e.g. ``range(2, 5, -1)`` or ``range(5, 5, 1)``).
  937. Examples:
  938. ::
  939. print(range(4)) # Prints [0, 1, 2, 3]
  940. print(range(2, 5)) # Prints [2, 3, 4]
  941. print(range(0, 6, 2)) # Prints [0, 2, 4]
  942. print(range(4, 1, -1)) # Prints [4, 3, 2]
  943. To iterate over an :ref:`Array<class_Array>` backwards, use:
  944. ::
  945. var array = [3, 6, 9]
  946. for i in range(array.size(), 0, -1):
  947. print(array[i - 1])
  948. Output:
  949. ::
  950. 9
  951. 6
  952. 3
  953. .. rst-class:: classref-item-separator
  954. ----
  955. .. _class_@GDScript_method_range_lerp:
  956. .. rst-class:: classref-method
  957. :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 **)**
  958. Maps a ``value`` from range ``[istart, istop]`` to ``[ostart, ostop]``. See also :ref:`lerp<class_@GDScript_method_lerp>` and :ref:`inverse_lerp<class_@GDScript_method_inverse_lerp>`. If ``value`` is outside ``[istart, istop]``, then the resulting value will also be outside ``[ostart, ostop]``. Use :ref:`clamp<class_@GDScript_method_clamp>` on the result of :ref:`range_lerp<class_@GDScript_method_range_lerp>` if this is not desired.
  959. ::
  960. range_lerp(75, 0, 100, -1, 1) # Returns 0.5
  961. For complex use cases where you need multiple ranges, consider using :ref:`Curve<class_Curve>` or :ref:`Gradient<class_Gradient>` instead.
  962. .. rst-class:: classref-item-separator
  963. ----
  964. .. _class_@GDScript_method_round:
  965. .. rst-class:: classref-method
  966. :ref:`float<class_float>` **round** **(** :ref:`float<class_float>` s **)**
  967. Rounds ``s`` to the nearest whole number, with halfway cases rounded away from zero.
  968. ::
  969. a = round(2.49) # a is 2.0
  970. a = round(2.5) # a is 3.0
  971. a = round(2.51) # a is 3.0
  972. See also :ref:`floor<class_@GDScript_method_floor>`, :ref:`ceil<class_@GDScript_method_ceil>`, :ref:`stepify<class_@GDScript_method_stepify>`, and :ref:`int<class_int>`.
  973. .. rst-class:: classref-item-separator
  974. ----
  975. .. _class_@GDScript_method_seed:
  976. .. rst-class:: classref-method
  977. void **seed** **(** :ref:`int<class_int>` seed **)**
  978. Sets seed for the random number generator.
  979. ::
  980. my_seed = "Godot Rocks"
  981. seed(my_seed.hash())
  982. .. rst-class:: classref-item-separator
  983. ----
  984. .. _class_@GDScript_method_sign:
  985. .. rst-class:: classref-method
  986. :ref:`float<class_float>` **sign** **(** :ref:`float<class_float>` s **)**
  987. Returns the sign of ``s``: -1 or 1. Returns 0 if ``s`` is 0.
  988. ::
  989. sign(-6) # Returns -1
  990. sign(0) # Returns 0
  991. sign(6) # Returns 1
  992. .. rst-class:: classref-item-separator
  993. ----
  994. .. _class_@GDScript_method_sin:
  995. .. rst-class:: classref-method
  996. :ref:`float<class_float>` **sin** **(** :ref:`float<class_float>` s **)**
  997. Returns the sine of angle ``s`` in radians.
  998. ::
  999. sin(0.523599) # Returns 0.5
  1000. .. rst-class:: classref-item-separator
  1001. ----
  1002. .. _class_@GDScript_method_sinh:
  1003. .. rst-class:: classref-method
  1004. :ref:`float<class_float>` **sinh** **(** :ref:`float<class_float>` s **)**
  1005. Returns the hyperbolic sine of ``s``.
  1006. ::
  1007. a = log(2.0) # Returns 0.693147
  1008. sinh(a) # Returns 0.75
  1009. .. rst-class:: classref-item-separator
  1010. ----
  1011. .. _class_@GDScript_method_smoothstep:
  1012. .. rst-class:: classref-method
  1013. :ref:`float<class_float>` **smoothstep** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` s **)**
  1014. Returns the result of smoothly interpolating the value of ``s`` between ``0`` and ``1``, based on the where ``s`` lies with respect to the edges ``from`` and ``to``.
  1015. The return value is ``0`` if ``s <= from``, and ``1`` if ``s >= to``. If ``s`` lies between ``from`` and ``to``, the returned value follows an S-shaped curve that maps ``s`` between ``0`` and ``1``.
  1016. This S-shaped curve is the cubic Hermite interpolator, given by ``f(y) = 3*y^2 - 2*y^3`` where ``y = (x-from) / (to-from)``.
  1017. ::
  1018. smoothstep(0, 2, -5.0) # Returns 0.0
  1019. smoothstep(0, 2, 0.5) # Returns 0.15625
  1020. smoothstep(0, 2, 1.0) # Returns 0.5
  1021. smoothstep(0, 2, 2.0) # Returns 1.0
  1022. Compared to :ref:`ease<class_@GDScript_method_ease>` with a curve value of ``-1.6521``, :ref:`smoothstep<class_@GDScript_method_smoothstep>` returns the smoothest possible curve with no sudden changes in the derivative. If you need to perform more advanced transitions, use :ref:`Tween<class_Tween>` or :ref:`AnimationPlayer<class_AnimationPlayer>`.
  1023. \ `Comparison between smoothstep() and ease(x, -1.6521) return values <https://raw.githubusercontent.com/godotengine/godot-docs/3.6/img/smoothstep_ease_comparison.png>`__
  1024. .. rst-class:: classref-item-separator
  1025. ----
  1026. .. _class_@GDScript_method_sqrt:
  1027. .. rst-class:: classref-method
  1028. :ref:`float<class_float>` **sqrt** **(** :ref:`float<class_float>` s **)**
  1029. Returns the square root of ``s``, where ``s`` is a non-negative number.
  1030. ::
  1031. sqrt(9) # Returns 3
  1032. \ **Note:** Negative values of ``s`` return NaN. If you need negative inputs, use ``System.Numerics.Complex`` in C#.
  1033. .. rst-class:: classref-item-separator
  1034. ----
  1035. .. _class_@GDScript_method_step_decimals:
  1036. .. rst-class:: classref-method
  1037. :ref:`int<class_int>` **step_decimals** **(** :ref:`float<class_float>` step **)**
  1038. Returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation.
  1039. ::
  1040. n = step_decimals(5) # n is 0
  1041. n = step_decimals(1.0005) # n is 4
  1042. n = step_decimals(0.000000005) # n is 9
  1043. .. rst-class:: classref-item-separator
  1044. ----
  1045. .. _class_@GDScript_method_stepify:
  1046. .. rst-class:: classref-method
  1047. :ref:`float<class_float>` **stepify** **(** :ref:`float<class_float>` s, :ref:`float<class_float>` step **)**
  1048. Snaps float value ``s`` to a given ``step``. This can also be used to round a floating point number to an arbitrary number of decimals.
  1049. ::
  1050. stepify(100, 32) # Returns 96.0
  1051. stepify(3.14159, 0.01) # Returns 3.14
  1052. See also :ref:`ceil<class_@GDScript_method_ceil>`, :ref:`floor<class_@GDScript_method_floor>`, :ref:`round<class_@GDScript_method_round>`, and :ref:`int<class_int>`.
  1053. .. rst-class:: classref-item-separator
  1054. ----
  1055. .. _class_@GDScript_method_str:
  1056. .. rst-class:: classref-method
  1057. :ref:`String<class_String>` **str** **(** ... **)** |vararg|
  1058. Converts one or more arguments of any type to string in the best way possible.
  1059. ::
  1060. var a = [10, 20, 30]
  1061. var b = str(a);
  1062. len(a) # Returns 3
  1063. len(b) # Returns 12
  1064. .. rst-class:: classref-item-separator
  1065. ----
  1066. .. _class_@GDScript_method_str2var:
  1067. .. rst-class:: classref-method
  1068. :ref:`Variant<class_Variant>` **str2var** **(** :ref:`String<class_String>` string **)**
  1069. Converts a formatted string that was returned by :ref:`var2str<class_@GDScript_method_var2str>` to the original value.
  1070. ::
  1071. a = '{ "a": 1, "b": 2 }'
  1072. b = str2var(a)
  1073. print(b["a"]) # Prints 1
  1074. .. rst-class:: classref-item-separator
  1075. ----
  1076. .. _class_@GDScript_method_tan:
  1077. .. rst-class:: classref-method
  1078. :ref:`float<class_float>` **tan** **(** :ref:`float<class_float>` s **)**
  1079. Returns the tangent of angle ``s`` in radians.
  1080. ::
  1081. tan(deg2rad(45)) # Returns 1
  1082. .. rst-class:: classref-item-separator
  1083. ----
  1084. .. _class_@GDScript_method_tanh:
  1085. .. rst-class:: classref-method
  1086. :ref:`float<class_float>` **tanh** **(** :ref:`float<class_float>` s **)**
  1087. Returns the hyperbolic tangent of ``s``.
  1088. ::
  1089. a = log(2.0) # a is 0.693147
  1090. b = tanh(a) # b is 0.6
  1091. .. rst-class:: classref-item-separator
  1092. ----
  1093. .. _class_@GDScript_method_to_json:
  1094. .. rst-class:: classref-method
  1095. :ref:`String<class_String>` **to_json** **(** :ref:`Variant<class_Variant>` var **)**
  1096. Converts a :ref:`Variant<class_Variant>` ``var`` to JSON text and return the result. Useful for serializing data to store or send over the network.
  1097. ::
  1098. # Both numbers below are integers.
  1099. a = { "a": 1, "b": 2 }
  1100. b = to_json(a)
  1101. print(b) # {"a":1, "b":2}
  1102. # Both numbers above are floats, even if they display without any decimal places.
  1103. \ **Note:** The JSON specification does not define integer or float types, but only a *number* type. Therefore, converting a :ref:`Variant<class_Variant>` to JSON text will convert all numerical values to :ref:`float<class_float>` types.
  1104. See also :ref:`JSON<class_JSON>` for an alternative way to convert a :ref:`Variant<class_Variant>` to JSON text.
  1105. .. rst-class:: classref-item-separator
  1106. ----
  1107. .. _class_@GDScript_method_type_exists:
  1108. .. rst-class:: classref-method
  1109. :ref:`bool<class_bool>` **type_exists** **(** :ref:`String<class_String>` type **)**
  1110. Returns whether the given class exists in :ref:`ClassDB<class_ClassDB>`.
  1111. ::
  1112. type_exists("Sprite") # Returns true
  1113. type_exists("Variant") # Returns false
  1114. .. rst-class:: classref-item-separator
  1115. ----
  1116. .. _class_@GDScript_method_typeof:
  1117. .. rst-class:: classref-method
  1118. :ref:`int<class_int>` **typeof** **(** :ref:`Variant<class_Variant>` what **)**
  1119. Returns the internal type of the given Variant object, using the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` values.
  1120. ::
  1121. p = parse_json('["a", "b", "c"]')
  1122. if typeof(p) == TYPE_ARRAY:
  1123. print(p[0]) # Prints a
  1124. else:
  1125. print("unexpected results")
  1126. .. rst-class:: classref-item-separator
  1127. ----
  1128. .. _class_@GDScript_method_validate_json:
  1129. .. rst-class:: classref-method
  1130. :ref:`String<class_String>` **validate_json** **(** :ref:`String<class_String>` json **)**
  1131. Checks that ``json`` is valid JSON data. Returns an empty string if valid, or an error message otherwise.
  1132. ::
  1133. j = to_json([1, 2, 3])
  1134. v = validate_json(j)
  1135. if not v:
  1136. print("Valid JSON.")
  1137. else:
  1138. push_error("Invalid JSON: " + v)
  1139. .. rst-class:: classref-item-separator
  1140. ----
  1141. .. _class_@GDScript_method_var2bytes:
  1142. .. rst-class:: classref-method
  1143. :ref:`PoolByteArray<class_PoolByteArray>` **var2bytes** **(** :ref:`Variant<class_Variant>` var, :ref:`bool<class_bool>` full_objects=false **)**
  1144. Encodes a variable value to a byte array. When ``full_objects`` is ``true`` encoding objects is allowed (and can potentially include code).
  1145. .. rst-class:: classref-item-separator
  1146. ----
  1147. .. _class_@GDScript_method_var2str:
  1148. .. rst-class:: classref-method
  1149. :ref:`String<class_String>` **var2str** **(** :ref:`Variant<class_Variant>` var **)**
  1150. Converts a Variant ``var`` to a formatted string that can later be parsed using :ref:`str2var<class_@GDScript_method_str2var>`.
  1151. ::
  1152. a = { "a": 1, "b": 2 }
  1153. print(var2str(a))
  1154. prints
  1155. ::
  1156. {
  1157. "a": 1,
  1158. "b": 2
  1159. }
  1160. .. rst-class:: classref-item-separator
  1161. ----
  1162. .. _class_@GDScript_method_weakref:
  1163. .. rst-class:: classref-method
  1164. :ref:`WeakRef<class_WeakRef>` **weakref** **(** :ref:`Object<class_Object>` obj **)**
  1165. Returns a weak reference to an object.
  1166. 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.
  1167. .. rst-class:: classref-item-separator
  1168. ----
  1169. .. _class_@GDScript_method_wrapf:
  1170. .. rst-class:: classref-method
  1171. :ref:`float<class_float>` **wrapf** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)**
  1172. Wraps float ``value`` between ``min`` and ``max``.
  1173. Usable for creating loop-alike behavior or infinite surfaces.
  1174. ::
  1175. # Infinite loop between 5.0 and 9.9
  1176. value = wrapf(value + 0.1, 5.0, 10.0)
  1177. ::
  1178. # Infinite rotation (in radians)
  1179. angle = wrapf(angle + 0.1, 0.0, TAU)
  1180. ::
  1181. # Infinite rotation (in radians)
  1182. angle = wrapf(angle + 0.1, -PI, PI)
  1183. \ **Note:** If ``min`` is ``0``, this is equivalent to :ref:`fposmod<class_@GDScript_method_fposmod>`, so prefer using that instead.
  1184. \ ``wrapf`` is more flexible than using the :ref:`fposmod<class_@GDScript_method_fposmod>` approach by giving the user control over the minimum value.
  1185. .. rst-class:: classref-item-separator
  1186. ----
  1187. .. _class_@GDScript_method_wrapi:
  1188. .. rst-class:: classref-method
  1189. :ref:`int<class_int>` **wrapi** **(** :ref:`int<class_int>` value, :ref:`int<class_int>` min, :ref:`int<class_int>` max **)**
  1190. Wraps integer ``value`` between ``min`` and ``max``.
  1191. Usable for creating loop-alike behavior or infinite surfaces.
  1192. ::
  1193. # Infinite loop between 5 and 9
  1194. frame = wrapi(frame + 1, 5, 10)
  1195. ::
  1196. # result is -2
  1197. var result = wrapi(-6, -5, -1)
  1198. \ **Note:** If ``min`` is ``0``, this is equivalent to :ref:`posmod<class_@GDScript_method_posmod>`, so prefer using that instead.
  1199. \ ``wrapi`` is more flexible than using the :ref:`posmod<class_@GDScript_method_posmod>` approach by giving the user control over the minimum value.
  1200. .. rst-class:: classref-item-separator
  1201. ----
  1202. .. _class_@GDScript_method_yield:
  1203. .. rst-class:: classref-method
  1204. :ref:`GDScriptFunctionState<class_GDScriptFunctionState>` **yield** **(** :ref:`Object<class_Object>` object=null, :ref:`String<class_String>` signal="" **)**
  1205. Stops the function execution and returns the current suspended state to the calling function.
  1206. From the caller, call :ref:`GDScriptFunctionState.resume<class_GDScriptFunctionState_method_resume>` on the state to resume execution. This invalidates the state. Within the resumed function, ``yield()`` returns whatever was passed to the ``resume()`` function call.
  1207. If passed an object and a signal, the execution is resumed when the object emits the given signal. In this case, ``yield()`` returns the argument passed to ``emit_signal()`` if the signal takes only one argument, or an array containing all the arguments passed to ``emit_signal()`` if the signal takes multiple arguments.
  1208. You can also use ``yield`` to wait for a function to finish:
  1209. ::
  1210. func _ready():
  1211. yield(countdown(), "completed") # waiting for the countdown() function to complete
  1212. print('Ready')
  1213. func countdown():
  1214. yield(get_tree(), "idle_frame") # returns a GDScriptFunctionState object to _ready()
  1215. print(3)
  1216. yield(get_tree().create_timer(1.0), "timeout")
  1217. print(2)
  1218. yield(get_tree().create_timer(1.0), "timeout")
  1219. print(1)
  1220. yield(get_tree().create_timer(1.0), "timeout")
  1221. # prints:
  1222. # 3
  1223. # 2
  1224. # 1
  1225. # Ready
  1226. When yielding on a function, the ``completed`` signal will be emitted automatically when the function returns. It can, therefore, be used as the ``signal`` parameter of the ``yield`` method to resume.
  1227. In order to yield on a function, the resulting function should also return a ``GDScriptFunctionState``. Notice ``yield(get_tree(), "idle_frame")`` from the above example.
  1228. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  1229. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  1230. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  1231. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`