Skip to content

Commit 7070b89

Browse files
author
Godot Organization
committed
classref: Sync with current master branch (5f1e56f)
1 parent 8b4cc3b commit 7070b89

16 files changed

+340
-43
lines changed

classes/[email protected]

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,8 @@ Returns a single character (as a :ref:`String<class_String>`) of the given Unico
815815

816816
:ref:`Variant<class_Variant>` **convert** **(** :ref:`Variant<class_Variant>` what, :ref:`int<class_int>` type **)**
817817

818+
*Deprecated.* Use :ref:`@GlobalScope.type_convert<class_@GlobalScope_method_type_convert>` instead.
819+
818820
Converts ``what`` to ``type`` in the best way possible. The ``type`` uses the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` values.
819821

820822
::

classes/[email protected]

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ Methods
331331
+-------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
332332
| :ref:`float<class_float>` | :ref:`tanh<class_@GlobalScope_method_tanh>` **(** :ref:`float<class_float>` x **)** |
333333
+-------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
334+
| :ref:`Variant<class_Variant>` | :ref:`type_convert<class_@GlobalScope_method_type_convert>` **(** :ref:`Variant<class_Variant>` variant, :ref:`int<class_int>` type **)** |
335+
+-------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
334336
| :ref:`int<class_int>` | :ref:`typeof<class_@GlobalScope_method_typeof>` **(** :ref:`Variant<class_Variant>` variable **)** |
335337
+-------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
336338
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`var_to_bytes<class_@GlobalScope_method_var_to_bytes>` **(** :ref:`Variant<class_Variant>` variable **)** |
@@ -6874,13 +6876,16 @@ Sets the seed for the random number generator to ``base``. Setting the seed manu
68746876

68756877
:ref:`Variant<class_Variant>` **sign** **(** :ref:`Variant<class_Variant>` x **)**
68766878

6877-
Returns the same type of :ref:`Variant<class_Variant>` as ``x``, with ``-1`` for negative values, ``1`` for positive values, and ``0`` for zeros. Supported types: :ref:`int<class_int>`, :ref:`float<class_float>`, :ref:`Vector2<class_Vector2>`, :ref:`Vector2i<class_Vector2i>`, :ref:`Vector3<class_Vector3>`, :ref:`Vector3i<class_Vector3i>`, :ref:`Vector4<class_Vector4>`, :ref:`Vector4i<class_Vector4i>`.
6879+
Returns the same type of :ref:`Variant<class_Variant>` as ``x``, with ``-1`` for negative values, ``1`` for positive values, and ``0`` for zeros. For ``nan`` values it returns 0.
6880+
6881+
Supported types: :ref:`int<class_int>`, :ref:`float<class_float>`, :ref:`Vector2<class_Vector2>`, :ref:`Vector2i<class_Vector2i>`, :ref:`Vector3<class_Vector3>`, :ref:`Vector3i<class_Vector3i>`, :ref:`Vector4<class_Vector4>`, :ref:`Vector4i<class_Vector4i>`.
68786882

68796883
::
68806884

68816885
sign(-6.0) # Returns -1
68826886
sign(0.0) # Returns 0
68836887
sign(6.0) # Returns 1
6888+
sign(NAN) # Returns 0
68846889
68856890
sign(Vector3(-6.0, 0.0, 6.0)) # Returns (-1, 0, 1)
68866891

@@ -6896,13 +6901,14 @@ Returns the same type of :ref:`Variant<class_Variant>` as ``x``, with ``-1`` for
68966901

68976902
:ref:`float<class_float>` **signf** **(** :ref:`float<class_float>` x **)**
68986903

6899-
Returns ``-1.0`` if ``x`` is negative, ``1.0`` if ``x`` is positive, and ``0.0`` if ``x`` is zero.
6904+
Returns ``-1.0`` if ``x`` is negative, ``1.0`` if ``x`` is positive, and ``0.0`` if ``x`` is zero. For ``nan`` values of ``x`` it returns 0.0.
69006905

69016906
::
69026907

69036908
signf(-6.5) # Returns -1.0
69046909
signf(0.0) # Returns 0.0
69056910
signf(6.5) # Returns 1.0
6911+
signf(NAN) # Returns 0.0
69066912

69076913
.. rst-class:: classref-item-separator
69086914

@@ -7169,6 +7175,30 @@ Returns the hyperbolic tangent of ``x``.
71697175

71707176
----
71717177

7178+
.. _class_@GlobalScope_method_type_convert:
7179+
7180+
.. rst-class:: classref-method
7181+
7182+
:ref:`Variant<class_Variant>` **type_convert** **(** :ref:`Variant<class_Variant>` variant, :ref:`int<class_int>` type **)**
7183+
7184+
Converts the given ``variant`` to the given ``type``, using the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` values. This method is generous with how it handles types, it can automatically convert between array types, convert numeric :ref:`String<class_String>`\ s to :ref:`int<class_int>`, and converting most things to :ref:`String<class_String>`.
7185+
7186+
If the type conversion cannot be done, this method will return the default value for that type, for example converting :ref:`Rect2<class_Rect2>` to :ref:`Vector2<class_Vector2>` will always return ``Vector2.ZERO``. This method will never show error messages as long as ``type`` is a valid Variant type.
7187+
7188+
The returned value is a :ref:`Variant<class_Variant>`, but the data inside and the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` will be the same as the requested type.
7189+
7190+
::
7191+
7192+
type_convert("Hi!", TYPE_INT) # Returns 0
7193+
type_convert("123", TYPE_INT) # Returns 123
7194+
type_convert(123.4, TYPE_INT) # Returns 123
7195+
type_convert(5, TYPE_VECTOR2) # Returns (0, 0)
7196+
type_convert("Hi!", TYPE_NIL) # Returns null
7197+
7198+
.. rst-class:: classref-item-separator
7199+
7200+
----
7201+
71727202
.. _class_@GlobalScope_method_typeof:
71737203

71747204
.. rst-class:: classref-method

0 commit comments

Comments
 (0)