|
@@ -1,5 +1,6 @@
|
|
.. Generated automatically by doc/tools/makerst.py in Godot's source tree.
|
|
.. Generated automatically by doc/tools/makerst.py in Godot's source tree.
|
|
-.. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
|
|
|
|
|
|
+.. DO NOT EDIT THIS FILE, but the @GDScript.xml source instead.
|
|
|
|
+.. The source is found in doc/classes or modules/<name>/doc_classes.
|
|
|
|
|
|
.. _class_@GDScript:
|
|
.. _class_@GDScript:
|
|
|
|
|
|
@@ -77,9 +78,9 @@ Member Functions
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`inverse_lerp<class_@GDScript_inverse_lerp>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` value **)** |
|
|
| :ref:`float<class_float>` | :ref:`inverse_lerp<class_@GDScript_inverse_lerp>` **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` value **)** |
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
-| :ref:`float<class_float>` | :ref:`is_inf<class_@GDScript_is_inf>` **(** :ref:`float<class_float>` s **)** |
|
|
|
|
|
|
+| :ref:`bool<class_bool>` | :ref:`is_inf<class_@GDScript_is_inf>` **(** :ref:`float<class_float>` s **)** |
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
-| :ref:`float<class_float>` | :ref:`is_nan<class_@GDScript_is_nan>` **(** :ref:`float<class_float>` s **)** |
|
|
|
|
|
|
+| :ref:`bool<class_bool>` | :ref:`is_nan<class_@GDScript_is_nan>` **(** :ref:`float<class_float>` s **)** |
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`len<class_@GDScript_len>` **(** :ref:`Variant<class_variant>` var **)** |
|
|
| :ref:`int<class_int>` | :ref:`len<class_@GDScript_len>` **(** :ref:`Variant<class_variant>` var **)** |
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
@@ -191,117 +192,228 @@ Member Function Description
|
|
|
|
|
|
- :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 **)**
|
|
- :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 **)**
|
|
|
|
|
|
-Make a color from red, green, blue and alpha. Arguments can range from 0 to 255.
|
|
|
|
|
|
+Returns a 32 bit color with red, green, blue and alpha channels. Each channel has 8 bits of information ranging from 0 to 255.
|
|
|
|
+
|
|
|
|
+``r8`` red channel
|
|
|
|
+
|
|
|
|
+``g8`` green channel
|
|
|
|
+
|
|
|
|
+``b8`` blue channel
|
|
|
|
+
|
|
|
|
+``a8`` alpha channel
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ red = Color8(255, 0, 0)
|
|
|
|
|
|
.. _class_@GDScript_ColorN:
|
|
.. _class_@GDScript_ColorN:
|
|
|
|
|
|
- :ref:`Color<class_color>` **ColorN** **(** :ref:`String<class_string>` name, :ref:`float<class_float>` alpha **)**
|
|
- :ref:`Color<class_color>` **ColorN** **(** :ref:`String<class_string>` name, :ref:`float<class_float>` alpha **)**
|
|
|
|
|
|
|
|
+Returns color ``name`` with ``alpha`` ranging from 0 to 1. Note: ``name`` is defined in color_names.inc.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ red = ColorN('red')
|
|
|
|
+
|
|
.. _class_@GDScript_abs:
|
|
.. _class_@GDScript_abs:
|
|
|
|
|
|
- :ref:`float<class_float>` **abs** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **abs** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the absolute value of parameter s (i.e. unsigned value, works for integer and float).
|
|
|
|
|
|
+Returns the absolute value of parameter ``s`` (i.e. unsigned value, works for integer and float).
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # a is 1
|
|
|
|
+ a = abs(-1)
|
|
|
|
|
|
.. _class_@GDScript_acos:
|
|
.. _class_@GDScript_acos:
|
|
|
|
|
|
- :ref:`float<class_float>` **acos** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **acos** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the principal value of the arc cosine of s, expressed in radians. In trigonometrics, arc cosine is the inverse operation of cosine.
|
|
|
|
|
|
+Returns the arc cosine of ``s`` in radians. Use to get the angle of cosine ``s``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # c is 0.523599 or 30 degrees if converted with rad2deg(s)
|
|
|
|
+ c = acos(0.866025)
|
|
|
|
|
|
.. _class_@GDScript_asin:
|
|
.. _class_@GDScript_asin:
|
|
|
|
|
|
- :ref:`float<class_float>` **asin** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **asin** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the principal value of the arc sine of s, expressed in radians. In trigonometrics, arc sine is the inverse operation of sine.
|
|
|
|
|
|
+Returns the arc sine of ``s`` in radians. Use to get the angle of sine ``s``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # s is 0.523599 or 30 degrees if converted with rad2deg(s)
|
|
|
|
+ s = asin(0.5)
|
|
|
|
|
|
.. _class_@GDScript_assert:
|
|
.. _class_@GDScript_assert:
|
|
|
|
|
|
- void **assert** **(** :ref:`bool<class_bool>` condition **)**
|
|
- void **assert** **(** :ref:`bool<class_bool>` condition **)**
|
|
|
|
|
|
-Assert that the condition is true. If the condition is false, generates an error.
|
|
|
|
|
|
+Assert that the ``condition`` is true. If the ``condition`` is false a fatal error is generated and the program is halted. Useful for debugging to make sure a value is always true.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # Speed should always be between 0 and 20
|
|
|
|
+ speed = -10
|
|
|
|
+ assert(speed < 20) # Is true and program continues
|
|
|
|
+ assert(speed >= 0) # Is false and program stops
|
|
|
|
+ assert(speed >= 0 && speed < 20) # Or combined
|
|
|
|
|
|
.. _class_@GDScript_atan:
|
|
.. _class_@GDScript_atan:
|
|
|
|
|
|
- :ref:`float<class_float>` **atan** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **atan** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the principal value of the arc tangent of s, expressed in radians. In trigonometrics, arc tangent is the inverse operation of tangent. Notice that because of the sign ambiguity, the function cannot determine with certainty in which quadrant the angle falls only by its tangent value. See :ref:`atan2<class_@GDScript_atan2>` for an alternative that takes a fractional argument instead.
|
|
|
|
|
|
+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``.
|
|
|
|
+
|
|
|
|
+The method cannot know in which quadrant the angle should fall. See :ref:`atan2<class_@GDScript_atan2>` if you always want an exact angle.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = atan(0.5) # a is 0.463648
|
|
|
|
|
|
.. _class_@GDScript_atan2:
|
|
.. _class_@GDScript_atan2:
|
|
|
|
|
|
- :ref:`float<class_float>` **atan2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
|
|
- :ref:`float<class_float>` **atan2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
|
|
|
|
|
|
-Returns the principal value of the arc tangent of y/x, expressed in radians. To compute the value, the function takes into account the sign of both arguments in order to determine the quadrant.
|
|
|
|
|
|
+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.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = atan(0,-1) # a is 3.141593
|
|
|
|
|
|
.. _class_@GDScript_bytes2var:
|
|
.. _class_@GDScript_bytes2var:
|
|
|
|
|
|
- :ref:`Variant<class_variant>` **bytes2var** **(** :ref:`PoolByteArray<class_poolbytearray>` bytes **)**
|
|
- :ref:`Variant<class_variant>` **bytes2var** **(** :ref:`PoolByteArray<class_poolbytearray>` bytes **)**
|
|
|
|
|
|
-Decode a byte array back to a value.
|
|
|
|
|
|
+Decodes a byte array back to a value.
|
|
|
|
|
|
.. _class_@GDScript_ceil:
|
|
.. _class_@GDScript_ceil:
|
|
|
|
|
|
- :ref:`float<class_float>` **ceil** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **ceil** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Rounds s upward, returning the smallest integral value that is not less than s.
|
|
|
|
|
|
+Rounds ``s`` upward, returning the smallest integral value that is not less than ``s``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ i = ceil(1.45) # i is 2
|
|
|
|
+ i = ceil(1.001) # i is 2
|
|
|
|
|
|
.. _class_@GDScript_char:
|
|
.. _class_@GDScript_char:
|
|
|
|
|
|
- :ref:`String<class_string>` **char** **(** :ref:`int<class_int>` ascii **)**
|
|
- :ref:`String<class_string>` **char** **(** :ref:`int<class_int>` ascii **)**
|
|
|
|
|
|
|
|
+Returns a character as a String of the given ASCII code.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # a is 'A'
|
|
|
|
+ a = char(65)
|
|
|
|
+ # a is 'a'
|
|
|
|
+ a = char(65+32)
|
|
|
|
+
|
|
.. _class_@GDScript_clamp:
|
|
.. _class_@GDScript_clamp:
|
|
|
|
|
|
- :ref:`float<class_float>` **clamp** **(** :ref:`float<class_float>` val, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)**
|
|
- :ref:`float<class_float>` **clamp** **(** :ref:`float<class_float>` val, :ref:`float<class_float>` min, :ref:`float<class_float>` max **)**
|
|
|
|
|
|
-Clamps a value between a minimum and maximum value.
|
|
|
|
|
|
+Clamps ``val`` and returns a value not less than ``min`` and not more than ``max``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ speed = 1000
|
|
|
|
+ # a is 20
|
|
|
|
+ a = clamp(speed, 1, 20)
|
|
|
|
+
|
|
|
|
+ speed = -10
|
|
|
|
+ # a is 1
|
|
|
|
+ a = clamp(speed, 1, 20)
|
|
|
|
|
|
.. _class_@GDScript_convert:
|
|
.. _class_@GDScript_convert:
|
|
|
|
|
|
- :ref:`Object<class_object>` **convert** **(** :ref:`Variant<class_variant>` what, :ref:`int<class_int>` type **)**
|
|
- :ref:`Object<class_object>` **convert** **(** :ref:`Variant<class_variant>` what, :ref:`int<class_int>` type **)**
|
|
|
|
|
|
-Convert from a type to another in the best way possible. The "type" parameter uses the enum TYPE\_\* in :ref:`@Global Scope<class_@global scope>`.
|
|
|
|
|
|
+Converts from a type to another in the best way possible. The ``type`` parameter uses the enum TYPE\_\* in :ref:`@Global Scope<class_@global scope>`.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = Vector2(1, 0)
|
|
|
|
+ # prints 1
|
|
|
|
+ print(a.length())
|
|
|
|
+ a = convert(a, TYPE_STRING)
|
|
|
|
+ # prints 6
|
|
|
|
+ # (1, 0) is 6 characters
|
|
|
|
+ print(a.length())
|
|
|
|
|
|
.. _class_@GDScript_cos:
|
|
.. _class_@GDScript_cos:
|
|
|
|
|
|
- :ref:`float<class_float>` **cos** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **cos** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the cosine of an angle of s radians.
|
|
|
|
|
|
+Returns the cosine of angle ``s`` in radians.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # prints 1 and -1
|
|
|
|
+ print(cos(PI\*2))
|
|
|
|
+ print(cos(PI))
|
|
|
|
|
|
.. _class_@GDScript_cosh:
|
|
.. _class_@GDScript_cosh:
|
|
|
|
|
|
- :ref:`float<class_float>` **cosh** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **cosh** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the hyperbolic cosine of s.
|
|
|
|
|
|
+Returns the hyperbolic cosine of ``s`` in radians.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # prints 1.543081
|
|
|
|
+ print(cosh(1))
|
|
|
|
|
|
.. _class_@GDScript_db2linear:
|
|
.. _class_@GDScript_db2linear:
|
|
|
|
|
|
- :ref:`float<class_float>` **db2linear** **(** :ref:`float<class_float>` db **)**
|
|
- :ref:`float<class_float>` **db2linear** **(** :ref:`float<class_float>` db **)**
|
|
|
|
|
|
-Convert from decibels to linear energy (audio).
|
|
|
|
|
|
+Converts from decibels to linear energy (audio).
|
|
|
|
|
|
.. _class_@GDScript_decimals:
|
|
.. _class_@GDScript_decimals:
|
|
|
|
|
|
- :ref:`float<class_float>` **decimals** **(** :ref:`float<class_float>` step **)**
|
|
- :ref:`float<class_float>` **decimals** **(** :ref:`float<class_float>` step **)**
|
|
|
|
|
|
-Return the amount of decimals in the floating point value.
|
|
|
|
|
|
+Returns the position of the first non-zero digit, after the decimal point.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # n is 2
|
|
|
|
+ n = decimals(0.035)
|
|
|
|
|
|
.. _class_@GDScript_dectime:
|
|
.. _class_@GDScript_dectime:
|
|
|
|
|
|
- :ref:`float<class_float>` **dectime** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` amount, :ref:`float<class_float>` step **)**
|
|
- :ref:`float<class_float>` **dectime** **(** :ref:`float<class_float>` value, :ref:`float<class_float>` amount, :ref:`float<class_float>` step **)**
|
|
|
|
|
|
-Decreases time by a specified amount.
|
|
|
|
|
|
+Returns the result of ``value`` decreased by ``step`` \* ``amount``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # a = 59
|
|
|
|
+ a = dectime(60, 10, 0.1))
|
|
|
|
|
|
.. _class_@GDScript_deg2rad:
|
|
.. _class_@GDScript_deg2rad:
|
|
|
|
|
|
- :ref:`float<class_float>` **deg2rad** **(** :ref:`float<class_float>` deg **)**
|
|
- :ref:`float<class_float>` **deg2rad** **(** :ref:`float<class_float>` deg **)**
|
|
|
|
|
|
-Convert from degrees to radians.
|
|
|
|
|
|
+Returns degrees converted to radians.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # r is 3.141593
|
|
|
|
+ r = deg2rad(180)
|
|
|
|
|
|
.. _class_@GDScript_dict2inst:
|
|
.. _class_@GDScript_dict2inst:
|
|
|
|
|
|
- :ref:`Object<class_object>` **dict2inst** **(** :ref:`Dictionary<class_dictionary>` dict **)**
|
|
- :ref:`Object<class_object>` **dict2inst** **(** :ref:`Dictionary<class_dictionary>` dict **)**
|
|
|
|
|
|
-Convert a previously converted instances to dictionary back into an instance. Useful for deserializing.
|
|
|
|
|
|
+Converts a previously converted instance to a dictionary, back into an instance. Useful for deserializing.
|
|
|
|
|
|
.. _class_@GDScript_ease:
|
|
.. _class_@GDScript_ease:
|
|
|
|
|
|
@@ -313,117 +425,226 @@ Easing function, based on exponent. 0 is constant, 1 is linear, 0 to 1 is ease-i
|
|
|
|
|
|
- :ref:`float<class_float>` **exp** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **exp** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the base-e exponential function of s, which is e raised to the power s: e^s.
|
|
|
|
|
|
+Raises the Euler's constant **e** to the power of ``s`` and returns it. **e** has an approximate value of 2.71828.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = exp(2) # approximately 7.39
|
|
|
|
|
|
.. _class_@GDScript_floor:
|
|
.. _class_@GDScript_floor:
|
|
|
|
|
|
- :ref:`float<class_float>` **floor** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **floor** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Rounds s downward, returning the largest integral value that is not greater than s.
|
|
|
|
|
|
+Rounds ``s`` to the closest smaller integer and returns it.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # a is 2
|
|
|
|
+ a = floor(2.99)
|
|
|
|
+ # a is -3
|
|
|
|
+ a = floor(-2.99)
|
|
|
|
|
|
.. _class_@GDScript_fmod:
|
|
.. _class_@GDScript_fmod:
|
|
|
|
|
|
- :ref:`float<class_float>` **fmod** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
|
|
- :ref:`float<class_float>` **fmod** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
|
|
|
|
|
|
-Returns the floating-point remainder of x/y (rounded towards zero):
|
|
|
|
|
|
+Returns the floating-point remainder of ``x/y``.
|
|
|
|
|
|
::
|
|
::
|
|
|
|
|
|
- fmod = x - tquot \* y
|
|
|
|
-
|
|
|
|
-Where tquot is the truncated (i.e., rounded towards zero) result of: x/y.
|
|
|
|
|
|
+ # remainder is 1.5
|
|
|
|
+ var remainder = fmod(7, 5.5)
|
|
|
|
|
|
.. _class_@GDScript_fposmod:
|
|
.. _class_@GDScript_fposmod:
|
|
|
|
|
|
- :ref:`float<class_float>` **fposmod** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
|
|
- :ref:`float<class_float>` **fposmod** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
|
|
|
|
|
|
-Module (remainder of x/y) that wraps equally in positive and negative.
|
|
|
|
|
|
+Returns the floating-point remainder of ``x/y`` that wraps equally in positive and negative.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ var i = -10;
|
|
|
|
+ while i < 0:
|
|
|
|
+ prints(i, fposmod(i, 10))
|
|
|
|
+ i += 1
|
|
|
|
+
|
|
|
|
+Produces:
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ -10 10
|
|
|
|
+ -9 1
|
|
|
|
+ -8 2
|
|
|
|
+ -7 3
|
|
|
|
+ -6 4
|
|
|
|
+ -5 5
|
|
|
|
+ -4 6
|
|
|
|
+ -3 7
|
|
|
|
+ -2 8
|
|
|
|
+ -1 9
|
|
|
|
|
|
.. _class_@GDScript_funcref:
|
|
.. _class_@GDScript_funcref:
|
|
|
|
|
|
- :ref:`Object<class_object>` **funcref** **(** :ref:`Object<class_object>` instance, :ref:`String<class_string>` funcname **)**
|
|
- :ref:`Object<class_object>` **funcref** **(** :ref:`Object<class_object>` instance, :ref:`String<class_string>` funcname **)**
|
|
|
|
|
|
-Return a reference to the specified function.
|
|
|
|
|
|
+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.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ func foo():
|
|
|
|
+ return("bar")
|
|
|
|
+
|
|
|
|
+ a = funcref(self, "foo")
|
|
|
|
+ print(a.call_func()) # prints bar
|
|
|
|
|
|
.. _class_@GDScript_hash:
|
|
.. _class_@GDScript_hash:
|
|
|
|
|
|
- :ref:`int<class_int>` **hash** **(** :ref:`Variant<class_variant>` var **)**
|
|
- :ref:`int<class_int>` **hash** **(** :ref:`Variant<class_variant>` var **)**
|
|
|
|
|
|
-Hash the variable passed and return an integer.
|
|
|
|
|
|
+Returns the integer hash of the variable passed.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ print(hash("a")) # prints 177670
|
|
|
|
|
|
.. _class_@GDScript_inst2dict:
|
|
.. _class_@GDScript_inst2dict:
|
|
|
|
|
|
- :ref:`Dictionary<class_dictionary>` **inst2dict** **(** :ref:`Object<class_object>` inst **)**
|
|
- :ref:`Dictionary<class_dictionary>` **inst2dict** **(** :ref:`Object<class_object>` inst **)**
|
|
|
|
|
|
-Convert a script class instance to a dictionary (useful for serializing).
|
|
|
|
|
|
+Returns the passed instance converted to a dictionary (useful for serializing).
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ var foo = "bar"
|
|
|
|
+ func _ready():
|
|
|
|
+ var d = inst2dict(self)
|
|
|
|
+ print(d.keys())
|
|
|
|
+ print(d.values())
|
|
|
|
+
|
|
|
|
+Prints out:
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ [@subpath, @path, foo]
|
|
|
|
+ [, res://test.gd, bar]
|
|
|
|
|
|
.. _class_@GDScript_instance_from_id:
|
|
.. _class_@GDScript_instance_from_id:
|
|
|
|
|
|
- :ref:`Object<class_object>` **instance_from_id** **(** :ref:`int<class_int>` instance_id **)**
|
|
- :ref:`Object<class_object>` **instance_from_id** **(** :ref:`int<class_int>` instance_id **)**
|
|
|
|
|
|
-Get an object by its ID.
|
|
|
|
|
|
+Returns the Object that corresponds to ``instance_id``. All Objects have a unique instance ID.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ var foo = "bar"
|
|
|
|
+ func _ready():
|
|
|
|
+ var id = get_instance_id()
|
|
|
|
+ var inst = instance_from_id(id)
|
|
|
|
+ print(inst.foo) # prints bar
|
|
|
|
|
|
.. _class_@GDScript_inverse_lerp:
|
|
.. _class_@GDScript_inverse_lerp:
|
|
|
|
|
|
- :ref:`float<class_float>` **inverse_lerp** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` value **)**
|
|
- :ref:`float<class_float>` **inverse_lerp** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` value **)**
|
|
|
|
|
|
|
|
+Returns a normalized value considering the given range.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ inverse_lerp(3, 5, 4) # returns 0.5
|
|
|
|
+
|
|
.. _class_@GDScript_is_inf:
|
|
.. _class_@GDScript_is_inf:
|
|
|
|
|
|
-- :ref:`float<class_float>` **is_inf** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
+- :ref:`bool<class_bool>` **is_inf** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns whether s is an infinity value (either positive infinity or negative infinity).
|
|
|
|
|
|
+Returns True/False whether ``s`` is an infinity value (either positive infinity or negative infinity).
|
|
|
|
|
|
.. _class_@GDScript_is_nan:
|
|
.. _class_@GDScript_is_nan:
|
|
|
|
|
|
-- :ref:`float<class_float>` **is_nan** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
+- :ref:`bool<class_bool>` **is_nan** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns whether s is a NaN (Not-A-Number) value.
|
|
|
|
|
|
+Returns True/False whether ``s`` is a NaN (Not-A-Number) value.
|
|
|
|
|
|
.. _class_@GDScript_len:
|
|
.. _class_@GDScript_len:
|
|
|
|
|
|
- :ref:`int<class_int>` **len** **(** :ref:`Variant<class_variant>` var **)**
|
|
- :ref:`int<class_int>` **len** **(** :ref:`Variant<class_variant>` var **)**
|
|
|
|
|
|
|
|
+Returns length of Variant ``var``. Length is the character count of String, element count of Array, size of Dictionary, etc. Note: Generates a fatal error if Variant can not provide a length.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = [1, 2, 3, 4]
|
|
|
|
+ len(a) # returns 4
|
|
|
|
+
|
|
.. _class_@GDScript_lerp:
|
|
.. _class_@GDScript_lerp:
|
|
|
|
|
|
- :ref:`float<class_float>` **lerp** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)**
|
|
- :ref:`float<class_float>` **lerp** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to, :ref:`float<class_float>` weight **)**
|
|
|
|
|
|
-Linear interpolates between two values by a normalized value.
|
|
|
|
|
|
+Linearly interpolates between two values by a normalized value.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ lerp(1, 3, 0.5) # returns 2
|
|
|
|
|
|
.. _class_@GDScript_linear2db:
|
|
.. _class_@GDScript_linear2db:
|
|
|
|
|
|
- :ref:`float<class_float>` **linear2db** **(** :ref:`float<class_float>` nrg **)**
|
|
- :ref:`float<class_float>` **linear2db** **(** :ref:`float<class_float>` nrg **)**
|
|
|
|
|
|
-Convert from linear energy to decibels (audio).
|
|
|
|
|
|
+Converts from linear energy to decibels (audio).
|
|
|
|
|
|
.. _class_@GDScript_load:
|
|
.. _class_@GDScript_load:
|
|
|
|
|
|
- :ref:`Object<class_object>` **load** **(** :ref:`String<class_string>` path **)**
|
|
- :ref:`Object<class_object>` **load** **(** :ref:`String<class_string>` path **)**
|
|
|
|
|
|
-Load a resource from the filesystem, pass a valid path as argument.
|
|
|
|
|
|
+Loads a resource from the filesystem located at 'path'. Note: resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path".
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # load a scene called main located in the root of the project directory
|
|
|
|
+ var main = load("res://main.tscn")
|
|
|
|
|
|
.. _class_@GDScript_log:
|
|
.. _class_@GDScript_log:
|
|
|
|
|
|
- :ref:`float<class_float>` **log** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **log** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Natural logarithm.
|
|
|
|
|
|
+Natural logarithm. The amount of time needed to reach a certain level of continuous growth. Note: This is not the same as the log function on your calculator which is a base 10 logarithm.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ log(10) # returns 2.302585
|
|
|
|
|
|
.. _class_@GDScript_max:
|
|
.. _class_@GDScript_max:
|
|
|
|
|
|
- :ref:`float<class_float>` **max** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
|
|
- :ref:`float<class_float>` **max** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
|
|
|
|
|
|
-Return the maximum of two values.
|
|
|
|
|
|
+Returns the maximum of two values.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ max(1,2) # returns 2
|
|
|
|
+ max(-3.99, -4) # returns -3.99
|
|
|
|
|
|
.. _class_@GDScript_min:
|
|
.. _class_@GDScript_min:
|
|
|
|
|
|
- :ref:`float<class_float>` **min** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
|
|
- :ref:`float<class_float>` **min** **(** :ref:`float<class_float>` a, :ref:`float<class_float>` b **)**
|
|
|
|
|
|
-Return the minimum of two values.
|
|
|
|
|
|
+Returns the minimum of two values.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ min(1,2) # returns 1
|
|
|
|
+ min(-3.99, -4) # returns -4
|
|
|
|
|
|
.. _class_@GDScript_nearest_po2:
|
|
.. _class_@GDScript_nearest_po2:
|
|
|
|
|
|
- :ref:`int<class_int>` **nearest_po2** **(** :ref:`int<class_int>` val **)**
|
|
- :ref:`int<class_int>` **nearest_po2** **(** :ref:`int<class_int>` val **)**
|
|
|
|
|
|
-Return the nearest larger power of 2 for an integer.
|
|
|
|
|
|
+Returns the nearest larger power of 2 for integer ``val``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ nearest_po2(3) # returns 4
|
|
|
|
+ nearest_po2(4) # returns 4
|
|
|
|
+ nearest_po2(5) # returns 8
|
|
|
|
|
|
.. _class_@GDScript_parse_json:
|
|
.. _class_@GDScript_parse_json:
|
|
|
|
|
|
@@ -431,207 +652,401 @@ Return the nearest larger power of 2 for an integer.
|
|
|
|
|
|
Parse JSON text to a Variant (use :ref:`typeof<class_@GDScript_typeof>` to check if it is what you expect).
|
|
Parse JSON text to a Variant (use :ref:`typeof<class_@GDScript_typeof>` to check if it is what you expect).
|
|
|
|
|
|
-Be aware that the JSON specification does not define integer or float types, but only a number type. Therefore, parsing a JSON text will convert every numerical values to :ref:`float<class_float>` types.
|
|
|
|
|
|
+Be aware that the JSON specification does not define integer or float types, but only a number type. Therefore, parsing a JSON text will convert all numerical values to :ref:`float<class_float>` types.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ p = parse_json('["a", "b", "c"]')
|
|
|
|
+ if typeof(p) == TYPE_ARRAY:
|
|
|
|
+ print(p[0]) # prints a
|
|
|
|
+ else:
|
|
|
|
+ print("unexpected results")
|
|
|
|
|
|
.. _class_@GDScript_pow:
|
|
.. _class_@GDScript_pow:
|
|
|
|
|
|
- :ref:`float<class_float>` **pow** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
|
|
- :ref:`float<class_float>` **pow** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y **)**
|
|
|
|
|
|
-Power function, x elevate to y.
|
|
|
|
|
|
+Returns the result of ``x`` raised to the power of ``y``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ pow(2,5) # returns 32
|
|
|
|
|
|
.. _class_@GDScript_preload:
|
|
.. _class_@GDScript_preload:
|
|
|
|
|
|
- :ref:`Resource<class_resource>` **preload** **(** :ref:`String<class_string>` path **)**
|
|
- :ref:`Resource<class_resource>` **preload** **(** :ref:`String<class_string>` path **)**
|
|
|
|
|
|
-Preload a resource from the filesystem. The resource is loaded during script parsing.
|
|
|
|
|
|
+Returns a resource from the filesystem that is loaded during script parsing. Note: resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path".
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ # load a scene called main located in the root of the project directory
|
|
|
|
+ var main = preload("res://main.tscn")
|
|
|
|
|
|
.. _class_@GDScript_print:
|
|
.. _class_@GDScript_print:
|
|
|
|
|
|
- void **print** **(** **)** vararg
|
|
- void **print** **(** **)** vararg
|
|
|
|
|
|
-Print one or more arguments to strings in the best way possible to a console line.
|
|
|
|
|
|
+Converts one or more arguments to strings in the best way possible and prints them to the console.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = [1,2,3]
|
|
|
|
+ print("a","b",a) # prints ab[1, 2, 3]
|
|
|
|
|
|
.. _class_@GDScript_print_stack:
|
|
.. _class_@GDScript_print_stack:
|
|
|
|
|
|
- void **print_stack** **(** **)**
|
|
- void **print_stack** **(** **)**
|
|
|
|
|
|
-Print a stack track at code location, only works when running with debugger turned on.
|
|
|
|
|
|
+Prints a stack track at code location, only works when running with debugger turned on.
|
|
|
|
+
|
|
|
|
+Output in the console would look something like this:
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ Frame 0 - res://test.gd:16 in function '_process'
|
|
|
|
|
|
.. _class_@GDScript_printerr:
|
|
.. _class_@GDScript_printerr:
|
|
|
|
|
|
- void **printerr** **(** **)** vararg
|
|
- void **printerr** **(** **)** vararg
|
|
|
|
|
|
-Print one or more arguments to strings in the best way possible to standard error line.
|
|
|
|
|
|
+Prints one or more arguments to strings in the best way possible to standard error line.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ printerr("prints to stderr")
|
|
|
|
|
|
.. _class_@GDScript_printraw:
|
|
.. _class_@GDScript_printraw:
|
|
|
|
|
|
- void **printraw** **(** **)** vararg
|
|
- void **printraw** **(** **)** vararg
|
|
|
|
|
|
-Print one or more arguments to strings in the best way possible to console. No newline is added at the end.
|
|
|
|
|
|
+Prints one or more arguments to strings in the best way possible to console. No newline is added at the end.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ printraw("A")
|
|
|
|
+ printraw("B")
|
|
|
|
+ # prints AB
|
|
|
|
|
|
.. _class_@GDScript_prints:
|
|
.. _class_@GDScript_prints:
|
|
|
|
|
|
- void **prints** **(** **)** vararg
|
|
- void **prints** **(** **)** vararg
|
|
|
|
|
|
-Print one or more arguments to the console with a space between each argument.
|
|
|
|
|
|
+Prints one or more arguments to the console with a space between each argument.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ prints("A", "B", "C") # prints A B C
|
|
|
|
|
|
.. _class_@GDScript_printt:
|
|
.. _class_@GDScript_printt:
|
|
|
|
|
|
- void **printt** **(** **)** vararg
|
|
- void **printt** **(** **)** vararg
|
|
|
|
|
|
-Print one or more arguments to the console with a tab between each argument.
|
|
|
|
|
|
+Prints one or more arguments to the console with a tab between each argument.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ printt("A", "B", "C") # prints A B C
|
|
|
|
|
|
.. _class_@GDScript_rad2deg:
|
|
.. _class_@GDScript_rad2deg:
|
|
|
|
|
|
- :ref:`float<class_float>` **rad2deg** **(** :ref:`float<class_float>` rad **)**
|
|
- :ref:`float<class_float>` **rad2deg** **(** :ref:`float<class_float>` rad **)**
|
|
|
|
|
|
-Convert from radians to degrees.
|
|
|
|
|
|
+Converts from radians to degrees.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ rad2deg(0.523599) # returns 30
|
|
|
|
|
|
.. _class_@GDScript_rand_range:
|
|
.. _class_@GDScript_rand_range:
|
|
|
|
|
|
- :ref:`float<class_float>` **rand_range** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to **)**
|
|
- :ref:`float<class_float>` **rand_range** **(** :ref:`float<class_float>` from, :ref:`float<class_float>` to **)**
|
|
|
|
|
|
-Random range, any floating point value between 'from' and 'to'.
|
|
|
|
|
|
+Random range, any floating point value between ``from`` and ``to``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ prints(rand_range(0, 1), rand_range(0, 1)) # prints 0.135591 0.405263
|
|
|
|
|
|
.. _class_@GDScript_rand_seed:
|
|
.. _class_@GDScript_rand_seed:
|
|
|
|
|
|
- :ref:`Array<class_array>` **rand_seed** **(** :ref:`int<class_int>` seed **)**
|
|
- :ref:`Array<class_array>` **rand_seed** **(** :ref:`int<class_int>` seed **)**
|
|
|
|
|
|
-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.
|
|
|
|
|
|
+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.
|
|
|
|
|
|
.. _class_@GDScript_randf:
|
|
.. _class_@GDScript_randf:
|
|
|
|
|
|
- :ref:`float<class_float>` **randf** **(** **)**
|
|
- :ref:`float<class_float>` **randf** **(** **)**
|
|
|
|
|
|
-Return a random floating point value between 0 and 1.
|
|
|
|
|
|
+Returns a random floating point value between 0 and 1.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ randf() # returns 0.375671
|
|
|
|
|
|
.. _class_@GDScript_randi:
|
|
.. _class_@GDScript_randi:
|
|
|
|
|
|
- :ref:`int<class_int>` **randi** **(** **)**
|
|
- :ref:`int<class_int>` **randi** **(** **)**
|
|
|
|
|
|
-Return a random 32 bits integer value. To obtain a random value between 0 to N (where N is smaller than 2^32 - 1), you can use remainder. For example, to get a random integer between 0 and 19 inclusive, you can use randi() % 20.
|
|
|
|
|
|
+Returns a random 32 bit integer. Use remainder to obtain a random value between 0 and N (where N is smaller than 2^32 -1).
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ randi() % 20 # returns random number between 0 and 19
|
|
|
|
+ randi() % 100 # returns random number between 0 and 99
|
|
|
|
+ randi() % 100 + 1 # returns random number between 1 and 100
|
|
|
|
|
|
.. _class_@GDScript_randomize:
|
|
.. _class_@GDScript_randomize:
|
|
|
|
|
|
- void **randomize** **(** **)**
|
|
- void **randomize** **(** **)**
|
|
|
|
|
|
-Randomize the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time.
|
|
|
|
|
|
+Randomizes the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ func _ready():
|
|
|
|
+ randomize()
|
|
|
|
|
|
.. _class_@GDScript_range:
|
|
.. _class_@GDScript_range:
|
|
|
|
|
|
- :ref:`Array<class_array>` **range** **(** **)** vararg
|
|
- :ref:`Array<class_array>` **range** **(** **)** vararg
|
|
|
|
|
|
-Return an array with the given range. Range can be 1 argument N (0 to N-1), two arguments (initial, final-1) or three arguments (initial, final-1, increment).
|
|
|
|
|
|
+Returns an array with the given range. Range can be 1 argument N (0 to N-1), two arguments (initial, final-1) or three arguments (initial, final-1, increment).
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ for i in range(4):
|
|
|
|
+ print(i)
|
|
|
|
+ for i in range(2, 5):
|
|
|
|
+ print(i)
|
|
|
|
+ for i in range(0, 6, 2):
|
|
|
|
+ print(i)
|
|
|
|
+
|
|
|
|
+Output:
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ 0
|
|
|
|
+ 1
|
|
|
|
+ 2
|
|
|
|
+ 3
|
|
|
|
+
|
|
|
|
+ 2
|
|
|
|
+ 3
|
|
|
|
+ 4
|
|
|
|
+
|
|
|
|
+ 0
|
|
|
|
+ 2
|
|
|
|
+ 4
|
|
|
|
|
|
.. _class_@GDScript_range_lerp:
|
|
.. _class_@GDScript_range_lerp:
|
|
|
|
|
|
- :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 **)**
|
|
- :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 **)**
|
|
|
|
|
|
|
|
+Maps a ``value`` from range ``[istart, istop]`` to ``[ostart, ostop]``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ range_lerp(75, 0, 100, -1, 1) # returns 0.5
|
|
|
|
+
|
|
.. _class_@GDScript_round:
|
|
.. _class_@GDScript_round:
|
|
|
|
|
|
- :ref:`float<class_float>` **round** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **round** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the integral value that is nearest to s, with halfway cases rounded away from zero.
|
|
|
|
|
|
+Returns the integral value that is nearest to ``s``, with halfway cases rounded away from zero.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ round(2.6) # returns 3
|
|
|
|
|
|
.. _class_@GDScript_seed:
|
|
.. _class_@GDScript_seed:
|
|
|
|
|
|
- void **seed** **(** :ref:`int<class_int>` seed **)**
|
|
- void **seed** **(** :ref:`int<class_int>` seed **)**
|
|
|
|
|
|
-Set seed for the random number generator.
|
|
|
|
|
|
+Sets seed for the random number generator.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ my_seed = "Godot Rocks"
|
|
|
|
+ seed(my_seed.hash())
|
|
|
|
|
|
.. _class_@GDScript_sign:
|
|
.. _class_@GDScript_sign:
|
|
|
|
|
|
- :ref:`float<class_float>` **sign** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **sign** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Return sign (-1 or +1).
|
|
|
|
|
|
+Returns sign of ``s`` -1 or 1.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ sign(-6) # returns -1
|
|
|
|
+ sign(6) # returns 1
|
|
|
|
|
|
.. _class_@GDScript_sin:
|
|
.. _class_@GDScript_sin:
|
|
|
|
|
|
- :ref:`float<class_float>` **sin** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **sin** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the sine of an angle of s radians.
|
|
|
|
|
|
+Returns the sine of angle ``s`` in radians.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ sin(0.523599) # returns 0.5
|
|
|
|
|
|
.. _class_@GDScript_sinh:
|
|
.. _class_@GDScript_sinh:
|
|
|
|
|
|
- :ref:`float<class_float>` **sinh** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **sinh** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the hyperbolic sine of s.
|
|
|
|
|
|
+Returns the hyperbolic sine of ``s``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = log(2.0) # returns 0.693147
|
|
|
|
+ sinh(a) # returns 0.75
|
|
|
|
|
|
.. _class_@GDScript_sqrt:
|
|
.. _class_@GDScript_sqrt:
|
|
|
|
|
|
- :ref:`float<class_float>` **sqrt** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **sqrt** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the square root of s.
|
|
|
|
|
|
+Returns the square root of ``s``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ sqrt(9) # returns 3
|
|
|
|
|
|
.. _class_@GDScript_stepify:
|
|
.. _class_@GDScript_stepify:
|
|
|
|
|
|
- :ref:`float<class_float>` **stepify** **(** :ref:`float<class_float>` s, :ref:`float<class_float>` step **)**
|
|
- :ref:`float<class_float>` **stepify** **(** :ref:`float<class_float>` s, :ref:`float<class_float>` step **)**
|
|
|
|
|
|
-Snap float value to a given step.
|
|
|
|
|
|
+Snaps float value ``s`` to a given ``step``.
|
|
|
|
|
|
.. _class_@GDScript_str:
|
|
.. _class_@GDScript_str:
|
|
|
|
|
|
- :ref:`String<class_string>` **str** **(** **)** vararg
|
|
- :ref:`String<class_string>` **str** **(** **)** vararg
|
|
|
|
|
|
-Convert one or more arguments to string in the best way possible.
|
|
|
|
|
|
+Converts one or more arguments to string in the best way possible.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ var a = [10, 20, 30]
|
|
|
|
+ var b = str(a);
|
|
|
|
+ len(a) # returns 3
|
|
|
|
+ len(b) # returns 12
|
|
|
|
|
|
.. _class_@GDScript_str2var:
|
|
.. _class_@GDScript_str2var:
|
|
|
|
|
|
- :ref:`Variant<class_variant>` **str2var** **(** :ref:`String<class_string>` string **)**
|
|
- :ref:`Variant<class_variant>` **str2var** **(** :ref:`String<class_string>` string **)**
|
|
|
|
|
|
-Convert a formatted string that was returned by :ref:`var2str<class_@GDScript_var2str>` to the original value.
|
|
|
|
|
|
+Converts a formatted string that was returned by :ref:`var2str<class_@GDScript_var2str>` to the original value.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = '{ "a": 1, "b": 2 }'
|
|
|
|
+ b = str2var(a)
|
|
|
|
+ print(b['a']) # prints 1
|
|
|
|
|
|
.. _class_@GDScript_tan:
|
|
.. _class_@GDScript_tan:
|
|
|
|
|
|
- :ref:`float<class_float>` **tan** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **tan** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the tangent of an angle of s radians.
|
|
|
|
|
|
+Returns the tangent of angle ``s`` in radians.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ tan( deg2rad(45) ) # returns 1
|
|
|
|
|
|
.. _class_@GDScript_tanh:
|
|
.. _class_@GDScript_tanh:
|
|
|
|
|
|
- :ref:`float<class_float>` **tanh** **(** :ref:`float<class_float>` s **)**
|
|
- :ref:`float<class_float>` **tanh** **(** :ref:`float<class_float>` s **)**
|
|
|
|
|
|
-Returns the hyperbolic tangent of s.
|
|
|
|
|
|
+Returns the hyperbolic tangent of ``s``.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = log(2.0) # returns 0.693147
|
|
|
|
+ tanh(a) # returns 0.6
|
|
|
|
|
|
.. _class_@GDScript_to_json:
|
|
.. _class_@GDScript_to_json:
|
|
|
|
|
|
- :ref:`String<class_string>` **to_json** **(** :ref:`Variant<class_variant>` var **)**
|
|
- :ref:`String<class_string>` **to_json** **(** :ref:`Variant<class_variant>` var **)**
|
|
|
|
|
|
-Convert a Variant to json text.
|
|
|
|
|
|
+Converts a Variant ``var`` to JSON text and return the result. Useful for serializing data to store or send over the network.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = { 'a': 1, 'b': 2 }
|
|
|
|
+ b = to_json(a)
|
|
|
|
+ print(b) # {"a":1, "b":2}
|
|
|
|
|
|
.. _class_@GDScript_type_exists:
|
|
.. _class_@GDScript_type_exists:
|
|
|
|
|
|
- :ref:`bool<class_bool>` **type_exists** **(** :ref:`String<class_string>` type **)**
|
|
- :ref:`bool<class_bool>` **type_exists** **(** :ref:`String<class_string>` type **)**
|
|
|
|
|
|
|
|
+Returns whether the given class exists in :ref:`ClassDB<class_classdb>`.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ type_exists("Sprite") # returns true
|
|
|
|
+ type_exists("Variant") # returns false
|
|
|
|
+
|
|
.. _class_@GDScript_typeof:
|
|
.. _class_@GDScript_typeof:
|
|
|
|
|
|
- :ref:`int<class_int>` **typeof** **(** :ref:`Variant<class_variant>` what **)**
|
|
- :ref:`int<class_int>` **typeof** **(** :ref:`Variant<class_variant>` what **)**
|
|
|
|
|
|
-Return the internal type of the given Variant object, using the TYPE\_\* enum in :ref:`@Global Scope<class_@global scope>`.
|
|
|
|
|
|
+Returns the internal type of the given Variant object, using the TYPE\_\* enum in :ref:`@Global Scope<class_@global scope>`.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ p = parse_json('["a", "b", "c"]')
|
|
|
|
+ if typeof(p) == TYPE_ARRAY:
|
|
|
|
+ print(p[0]) # prints a
|
|
|
|
+ else:
|
|
|
|
+ print("unexpected results")
|
|
|
|
|
|
.. _class_@GDScript_validate_json:
|
|
.. _class_@GDScript_validate_json:
|
|
|
|
|
|
- :ref:`String<class_string>` **validate_json** **(** :ref:`String<class_string>` json **)**
|
|
- :ref:`String<class_string>` **validate_json** **(** :ref:`String<class_string>` json **)**
|
|
|
|
|
|
-This method is used to validate the structure and data types of a piece of JSON, similar to XML Schema for XML.
|
|
|
|
|
|
+Checks that ``json`` is valid JSON data. Returns empty string if valid. Returns error message if not valid.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ j = to_json([1, 2, 3])
|
|
|
|
+ v = validate_json(j)
|
|
|
|
+ if not v:
|
|
|
|
+ print("valid")
|
|
|
|
+ else:
|
|
|
|
+ prints("invalid", v)
|
|
|
|
|
|
.. _class_@GDScript_var2bytes:
|
|
.. _class_@GDScript_var2bytes:
|
|
|
|
|
|
- :ref:`PoolByteArray<class_poolbytearray>` **var2bytes** **(** :ref:`Variant<class_variant>` var **)**
|
|
- :ref:`PoolByteArray<class_poolbytearray>` **var2bytes** **(** :ref:`Variant<class_variant>` var **)**
|
|
|
|
|
|
-Encode a variable value to a byte array.
|
|
|
|
|
|
+Encodes a variable value to a byte array.
|
|
|
|
|
|
.. _class_@GDScript_var2str:
|
|
.. _class_@GDScript_var2str:
|
|
|
|
|
|
- :ref:`String<class_string>` **var2str** **(** :ref:`Variant<class_variant>` var **)**
|
|
- :ref:`String<class_string>` **var2str** **(** :ref:`Variant<class_variant>` var **)**
|
|
|
|
|
|
-Convert a value to a formatted string that can later be parsed using :ref:`str2var<class_@GDScript_str2var>`.
|
|
|
|
|
|
+Converts a Variant ``var`` to a formatted string that can later be parsed using :ref:`str2var<class_@GDScript_str2var>`.
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ a = { 'a': 1, 'b': 2 }
|
|
|
|
+ print(var2str(a))
|
|
|
|
+
|
|
|
|
+prints
|
|
|
|
+
|
|
|
|
+::
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+ "a": 1,
|
|
|
|
+ "b": 2
|
|
|
|
+ }
|
|
|
|
|
|
.. _class_@GDScript_weakref:
|
|
.. _class_@GDScript_weakref:
|
|
|
|
|
|
- :ref:`Object<class_object>` **weakref** **(** :ref:`Object<class_object>` obj **)**
|
|
- :ref:`Object<class_object>` **weakref** **(** :ref:`Object<class_object>` obj **)**
|
|
|
|
|
|
-Return a weak reference to an object.
|
|
|
|
|
|
+Returns a weak reference to an object.
|
|
|
|
|
|
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.
|
|
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.
|
|
|
|
|
|
@@ -639,7 +1054,7 @@ A weak reference to an object is not enough to keep the object alive: when the o
|
|
|
|
|
|
- :ref:`GDFunctionState<class_gdfunctionstate>` **yield** **(** :ref:`Object<class_object>` object, :ref:`String<class_string>` signal **)**
|
|
- :ref:`GDFunctionState<class_gdfunctionstate>` **yield** **(** :ref:`Object<class_object>` object, :ref:`String<class_string>` signal **)**
|
|
|
|
|
|
-Stop the function execution and return the current state. Call :ref:`GDFunctionState.resume<class_GDFunctionState_resume>` on the state to resume execution. This invalidates the state.
|
|
|
|
|
|
+Stops the function execution and returns the current state. Call :ref:`GDFunctionState.resume<class_GDFunctionState_resume>` on the state to resume execution. This invalidates the state.
|
|
|
|
|
|
Returns anything that was passed to the resume function call. If passed an object and a signal, the execution is resumed when the object's signal is emitted.
|
|
Returns anything that was passed to the resume function call. If passed an object and a signal, the execution is resumed when the object's signal is emitted.
|
|
|
|
|