classref: Sync with current master branch (96cdbbe)

This commit is contained in:
Godot Organization
2025-02-15 03:21:09 +00:00
parent 4f3c3fc101
commit b55955c3ce
427 changed files with 4074 additions and 3919 deletions
+50 -50
View File
@@ -46,11 +46,11 @@ An array data structure that can contain a sequence of elements of any :ref:`Var
\ **Note:** Arrays are always passed by **reference**. To get a copy of an array that can be modified independently of the original array, use :ref:`duplicate<class_Array_method_duplicate>`.
\ **Note:** Arrays are always passed by **reference**. To get a copy of an array that can be modified independently of the original array, use :ref:`duplicate()<class_Array_method_duplicate>`.
\ **Note:** Erasing elements while iterating over arrays is **not** supported and will result in unpredictable behavior.
\ **Differences between packed arrays, typed arrays, and untyped arrays:** Packed arrays are generally faster to iterate on and modify compared to a typed array of the same type (e.g. :ref:`PackedInt64Array<class_PackedInt64Array>` versus ``Array[int]``). Also, packed arrays consume less memory. As a downside, packed arrays are less flexible as they don't offer as many convenience methods such as :ref:`map<class_Array_method_map>`. Typed arrays are in turn faster to iterate on and modify than untyped arrays.
\ **Differences between packed arrays, typed arrays, and untyped arrays:** Packed arrays are generally faster to iterate on and modify compared to a typed array of the same type (e.g. :ref:`PackedInt64Array<class_PackedInt64Array>` versus ``Array[int]``). Also, packed arrays consume less memory. As a downside, packed arrays are less flexible as they don't offer as many convenience methods such as :ref:`map()<class_Array_method_map>`. Typed arrays are in turn faster to iterate on and modify than untyped arrays.
.. note::
@@ -257,7 +257,7 @@ Creates a typed array from the ``base`` array. A typed array can only contain el
- ``type`` is the built-in :ref:`Variant<class_Variant>` type, as one the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` constants.
- ``class_name`` is the built-in class name (see :ref:`Object.get_class<class_Object_method_get_class>`).
- ``class_name`` is the built-in class name (see :ref:`Object.get_class()<class_Object_method_get_class>`).
- ``script`` is the associated script. It must be a :ref:`Script<class_Script>` instance or ``null``.
@@ -297,7 +297,7 @@ In GDScript, this constructor is usually not necessary, as it is possible to cre
:ref:`Array<class_Array>` **Array**\ (\ from\: :ref:`Array<class_Array>`\ )
Returns the same array as ``from``. If you need a copy of the array, use :ref:`duplicate<class_Array_method_duplicate>`.
Returns the same array as ``from``. If you need a copy of the array, use :ref:`duplicate()<class_Array_method_duplicate>`.
.. rst-class:: classref-item-separator
@@ -459,9 +459,9 @@ The ``method`` should take one :ref:`Variant<class_Variant>` parameter (the curr
See also :ref:`any<class_Array_method_any>`, :ref:`filter<class_Array_method_filter>`, :ref:`map<class_Array_method_map>` and :ref:`reduce<class_Array_method_reduce>`.
See also :ref:`any()<class_Array_method_any>`, :ref:`filter()<class_Array_method_filter>`, :ref:`map()<class_Array_method_map>` and :ref:`reduce()<class_Array_method_reduce>`.
\ **Note:** Unlike relying on the size of an array returned by :ref:`filter<class_Array_method_filter>`, this method will return as early as possible to improve performance (especially with large arrays).
\ **Note:** Unlike relying on the size of an array returned by :ref:`filter()<class_Array_method_filter>`, this method will return as early as possible to improve performance (especially with large arrays).
\ **Note:** For an empty array, this method `always <https://en.wikipedia.org/wiki/Vacuous_truth>`__ returns ``true``.
@@ -493,9 +493,9 @@ The ``method`` should take one :ref:`Variant<class_Variant>` parameter (the curr
# Same as the first line above, but using a lambda function.
print([6, 10, 6].any(func(number): return number > 5)) # Prints true
See also :ref:`all<class_Array_method_all>`, :ref:`filter<class_Array_method_filter>`, :ref:`map<class_Array_method_map>` and :ref:`reduce<class_Array_method_reduce>`.
See also :ref:`all()<class_Array_method_all>`, :ref:`filter()<class_Array_method_filter>`, :ref:`map()<class_Array_method_map>` and :ref:`reduce()<class_Array_method_reduce>`.
\ **Note:** Unlike relying on the size of an array returned by :ref:`filter<class_Array_method_filter>`, this method will return as early as possible to improve performance (especially with large arrays).
\ **Note:** Unlike relying on the size of an array returned by :ref:`filter()<class_Array_method_filter>`, this method will return as early as possible to improve performance (especially with large arrays).
\ **Note:** For an empty array, this method always returns ``false``.
@@ -509,7 +509,7 @@ See also :ref:`all<class_Array_method_all>`, :ref:`filter<class_Array_method_fil
|void| **append**\ (\ value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Array_method_append>`
Appends ``value`` at the end of the array (alias of :ref:`push_back<class_Array_method_push_back>`).
Appends ``value`` at the end of the array (alias of :ref:`push_back()<class_Array_method_push_back>`).
.. rst-class:: classref-item-separator
@@ -552,7 +552,7 @@ Assigns elements of another ``array`` into the array. Resizes the array to match
:ref:`Variant<class_Variant>` **back**\ (\ ) |const| :ref:`🔗<class_Array_method_back>`
Returns the last element of the array. If the array is empty, fails and returns ``null``. See also :ref:`front<class_Array_method_front>`.
Returns the last element of the array. If the array is empty, fails and returns ``null``. See also :ref:`front()<class_Array_method_front>`.
\ **Note:** Unlike with the ``[]`` operator (``array[-1]``), an error is generated without stopping project execution.
@@ -582,7 +582,7 @@ If ``before`` is ``true`` (as by default), the returned index comes before all e
print(fruits.bsearch("Lemon", true)) # Prints 1, points at the first "Lemon".
print(fruits.bsearch("Lemon", false)) # Prints 3, points at "Orange".
\ **Note:** Calling :ref:`bsearch<class_Array_method_bsearch>` on an *unsorted* array will result in unexpected behavior. Use :ref:`sort<class_Array_method_sort>` before calling this method.
\ **Note:** Calling :ref:`bsearch()<class_Array_method_bsearch>` on an *unsorted* array will result in unexpected behavior. Use :ref:`sort()<class_Array_method_sort>` before calling this method.
.. rst-class:: classref-item-separator
@@ -596,7 +596,7 @@ If ``before`` is ``true`` (as by default), the returned index comes before all e
Returns the index of ``value`` in the sorted array. If it cannot be found, returns where ``value`` should be inserted to keep the array sorted (using ``func`` for the comparisons). The algorithm used is `binary search <https://en.wikipedia.org/wiki/Binary_search_algorithm>`__.
Similar to :ref:`sort_custom<class_Array_method_sort_custom>`, ``func`` is called as many times as necessary, receiving one array element and ``value`` as arguments. The function should return ``true`` if the array element should be *behind* ``value``, otherwise it should return ``false``.
Similar to :ref:`sort_custom()<class_Array_method_sort_custom>`, ``func`` is called as many times as necessary, receiving one array element and ``value`` as arguments. The function should return ``true`` if the array element should be *behind* ``value``, otherwise it should return ``false``.
If ``before`` is ``true`` (as by default), the returned index comes before all existing elements equal to ``value`` in the array.
@@ -621,7 +621,7 @@ If ``before`` is ``true`` (as by default), the returned index comes before all e
# Prints [["Tomato", 2], ["Apple", 5], ["Kiwi", 5], ["Banana", 5], ["Rice", 9]]
print(my_items)
\ **Note:** Calling :ref:`bsearch_custom<class_Array_method_bsearch_custom>` on an *unsorted* array will result in unexpected behavior. Use :ref:`sort_custom<class_Array_method_sort_custom>` with ``func`` before calling this method.
\ **Note:** Calling :ref:`bsearch_custom()<class_Array_method_bsearch_custom>` on an *unsorted* array will result in unexpected behavior. Use :ref:`sort_custom()<class_Array_method_sort_custom>` with ``func`` before calling this method.
.. rst-class:: classref-item-separator
@@ -633,7 +633,7 @@ If ``before`` is ``true`` (as by default), the returned index comes before all e
|void| **clear**\ (\ ) :ref:`🔗<class_Array_method_clear>`
Removes all elements from the array. This is equivalent to using :ref:`resize<class_Array_method_resize>` with a size of ``0``.
Removes all elements from the array. This is equivalent to using :ref:`resize()<class_Array_method_resize>` with a size of ``0``.
.. rst-class:: classref-item-separator
@@ -647,7 +647,7 @@ Removes all elements from the array. This is equivalent to using :ref:`resize<cl
Returns the number of times an element is in the array.
To count how many elements in an array satisfy a condition, see :ref:`reduce<class_Array_method_reduce>`.
To count how many elements in an array satisfy a condition, see :ref:`reduce()<class_Array_method_reduce>`.
.. rst-class:: classref-item-separator
@@ -675,7 +675,7 @@ If ``deep`` is ``true``, a **deep** copy is returned: all nested arrays and dict
|void| **erase**\ (\ value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Array_method_erase>`
Finds and removes the first occurrence of ``value`` from the array. If ``value`` does not exist in the array, nothing happens. To remove an element by index, use :ref:`remove_at<class_Array_method_remove_at>` instead.
Finds and removes the first occurrence of ``value`` from the array. If ``value`` does not exist in the array, nothing happens. To remove an element by index, use :ref:`remove_at()<class_Array_method_remove_at>` instead.
\ **Note:** This method shifts every element's index after the removed ``value`` back, which may have a noticeable performance cost, especially on larger arrays.
@@ -693,7 +693,7 @@ Finds and removes the first occurrence of ``value`` from the array. If ``value``
Assigns the given ``value`` to all elements in the array.
This method can often be combined with :ref:`resize<class_Array_method_resize>` to create an array with a given size and initialized elements:
This method can often be combined with :ref:`resize()<class_Array_method_resize>` to create an array with a given size and initialized elements:
.. tabs::
@@ -741,7 +741,7 @@ The ``method`` receives one of the array elements as an argument, and should ret
# Same as above, but using a lambda function.
print([1, 4, 5, 8].filter(func(number): return number % 2 == 0))
See also :ref:`any<class_Array_method_any>`, :ref:`all<class_Array_method_all>`, :ref:`map<class_Array_method_map>` and :ref:`reduce<class_Array_method_reduce>`.
See also :ref:`any()<class_Array_method_any>`, :ref:`all()<class_Array_method_all>`, :ref:`map()<class_Array_method_map>` and :ref:`reduce()<class_Array_method_reduce>`.
.. rst-class:: classref-item-separator
@@ -755,7 +755,7 @@ See also :ref:`any<class_Array_method_any>`, :ref:`all<class_Array_method_all>`,
Returns the index of the **first** occurrence of ``what`` in this array, or ``-1`` if there are none. The search's start can be specified with ``from``, continuing to the end of the array.
\ **Note:** If you just want to know whether the array contains ``what``, use :ref:`has<class_Array_method_has>` (``Contains`` in C#). In GDScript, you may also use the ``in`` operator.
\ **Note:** If you just want to know whether the array contains ``what``, use :ref:`has()<class_Array_method_has>` (``Contains`` in C#). In GDScript, you may also use the ``in`` operator.
\ **Note:** For performance reasons, the search is affected by ``what``'s :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`. For example, ``7`` (:ref:`int<class_int>`) and ``7.0`` (:ref:`float<class_float>`) are not considered equal for this method.
@@ -773,7 +773,7 @@ Returns the index of the **first** element in the array that causes ``method`` t
\ ``method`` is a callable that takes an element of the array, and returns a :ref:`bool<class_bool>`.
\ **Note:** If you just want to know whether the array contains *anything* that satisfies ``method``, use :ref:`any<class_Array_method_any>`.
\ **Note:** If you just want to know whether the array contains *anything* that satisfies ``method``, use :ref:`any()<class_Array_method_any>`.
.. tabs::
@@ -798,7 +798,7 @@ Returns the index of the **first** element in the array that causes ``method`` t
:ref:`Variant<class_Variant>` **front**\ (\ ) |const| :ref:`🔗<class_Array_method_front>`
Returns the first element of the array. If the array is empty, fails and returns ``null``. See also :ref:`back<class_Array_method_back>`.
Returns the first element of the array. If the array is empty, fails and returns ``null``. See also :ref:`back()<class_Array_method_back>`.
\ **Note:** Unlike with the ``[]`` operator (``array[0]``), an error is generated without stopping project execution.
@@ -824,7 +824,7 @@ Returns the element at the given ``index`` in the array. This is the same as usi
:ref:`int<class_int>` **get_typed_builtin**\ (\ ) |const| :ref:`🔗<class_Array_method_get_typed_builtin>`
Returns the built-in :ref:`Variant<class_Variant>` type of the typed array as a :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` constant. If the array is not typed, returns :ref:`@GlobalScope.TYPE_NIL<class_@GlobalScope_constant_TYPE_NIL>`. See also :ref:`is_typed<class_Array_method_is_typed>`.
Returns the built-in :ref:`Variant<class_Variant>` type of the typed array as a :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` constant. If the array is not typed, returns :ref:`@GlobalScope.TYPE_NIL<class_@GlobalScope_constant_TYPE_NIL>`. See also :ref:`is_typed()<class_Array_method_is_typed>`.
.. rst-class:: classref-item-separator
@@ -836,7 +836,7 @@ Returns the built-in :ref:`Variant<class_Variant>` type of the typed array as a
:ref:`StringName<class_StringName>` **get_typed_class_name**\ (\ ) |const| :ref:`🔗<class_Array_method_get_typed_class_name>`
Returns the **built-in** class name of the typed array, if the built-in :ref:`Variant<class_Variant>` type :ref:`@GlobalScope.TYPE_OBJECT<class_@GlobalScope_constant_TYPE_OBJECT>`. Otherwise, returns an empty :ref:`StringName<class_StringName>`. See also :ref:`is_typed<class_Array_method_is_typed>` and :ref:`Object.get_class<class_Object_method_get_class>`.
Returns the **built-in** class name of the typed array, if the built-in :ref:`Variant<class_Variant>` type :ref:`@GlobalScope.TYPE_OBJECT<class_@GlobalScope_constant_TYPE_OBJECT>`. Otherwise, returns an empty :ref:`StringName<class_StringName>`. See also :ref:`is_typed()<class_Array_method_is_typed>` and :ref:`Object.get_class()<class_Object_method_get_class>`.
.. rst-class:: classref-item-separator
@@ -848,7 +848,7 @@ Returns the **built-in** class name of the typed array, if the built-in :ref:`Va
:ref:`Variant<class_Variant>` **get_typed_script**\ (\ ) |const| :ref:`🔗<class_Array_method_get_typed_script>`
Returns the :ref:`Script<class_Script>` instance associated with this typed array, or ``null`` if it does not exist. See also :ref:`is_typed<class_Array_method_is_typed>`.
Returns the :ref:`Script<class_Script>` instance associated with this typed array, or ``null`` if it does not exist. See also :ref:`is_typed()<class_Array_method_is_typed>`.
.. rst-class:: classref-item-separator
@@ -916,7 +916,7 @@ Returns a hashed 32-bit integer value representing the array and its contents.
:ref:`int<class_int>` **insert**\ (\ position\: :ref:`int<class_int>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Array_method_insert>`
Inserts a new element (``value``) at a given index (``position``) in the array. ``position`` should be between ``0`` and the array's :ref:`size<class_Array_method_size>`.
Inserts a new element (``value``) at a given index (``position``) in the array. ``position`` should be between ``0`` and the array's :ref:`size()<class_Array_method_size>`.
Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, or one of the other :ref:`Error<enum_@GlobalScope_Error>` constants if this method fails.
@@ -932,7 +932,7 @@ Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, or on
:ref:`bool<class_bool>` **is_empty**\ (\ ) |const| :ref:`🔗<class_Array_method_is_empty>`
Returns ``true`` if the array is empty (``[]``). See also :ref:`size<class_Array_method_size>`.
Returns ``true`` if the array is empty (``[]``). See also :ref:`size()<class_Array_method_size>`.
.. rst-class:: classref-item-separator
@@ -944,7 +944,7 @@ Returns ``true`` if the array is empty (``[]``). See also :ref:`size<class_Array
:ref:`bool<class_bool>` **is_read_only**\ (\ ) |const| :ref:`🔗<class_Array_method_is_read_only>`
Returns ``true`` if the array is read-only. See :ref:`make_read_only<class_Array_method_make_read_only>`.
Returns ``true`` if the array is read-only. See :ref:`make_read_only()<class_Array_method_make_read_only>`.
In GDScript, arrays are automatically read-only if declared with the ``const`` keyword.
@@ -958,7 +958,7 @@ In GDScript, arrays are automatically read-only if declared with the ``const`` k
:ref:`bool<class_bool>` **is_same_typed**\ (\ array\: :ref:`Array<class_Array>`\ ) |const| :ref:`🔗<class_Array_method_is_same_typed>`
Returns ``true`` if this array is typed the same as the given ``array``. See also :ref:`is_typed<class_Array_method_is_typed>`.
Returns ``true`` if this array is typed the same as the given ``array``. See also :ref:`is_typed()<class_Array_method_is_typed>`.
.. rst-class:: classref-item-separator
@@ -1018,7 +1018,7 @@ The ``method`` should take one :ref:`Variant<class_Variant>` parameter (the curr
# Same as above, but using a lambda function.
print([1, 2, 3].map(func(element): return element * 2))
See also :ref:`filter<class_Array_method_filter>`, :ref:`reduce<class_Array_method_reduce>`, :ref:`any<class_Array_method_any>` and :ref:`all<class_Array_method_all>`.
See also :ref:`filter()<class_Array_method_filter>`, :ref:`reduce()<class_Array_method_reduce>`, :ref:`any()<class_Array_method_any>` and :ref:`all()<class_Array_method_all>`.
.. rst-class:: classref-item-separator
@@ -1030,9 +1030,9 @@ See also :ref:`filter<class_Array_method_filter>`, :ref:`reduce<class_Array_meth
:ref:`Variant<class_Variant>` **max**\ (\ ) |const| :ref:`🔗<class_Array_method_max>`
Returns the maximum value contained in the array, if all elements can be compared. Otherwise, returns ``null``. See also :ref:`min<class_Array_method_min>`.
Returns the maximum value contained in the array, if all elements can be compared. Otherwise, returns ``null``. See also :ref:`min()<class_Array_method_min>`.
To find the maximum value using a custom comparator, you can use :ref:`reduce<class_Array_method_reduce>`.
To find the maximum value using a custom comparator, you can use :ref:`reduce()<class_Array_method_reduce>`.
.. rst-class:: classref-item-separator
@@ -1044,7 +1044,7 @@ To find the maximum value using a custom comparator, you can use :ref:`reduce<cl
:ref:`Variant<class_Variant>` **min**\ (\ ) |const| :ref:`🔗<class_Array_method_min>`
Returns the minimum value contained in the array, if all elements can be compared. Otherwise, returns ``null``. See also :ref:`max<class_Array_method_max>`.
Returns the minimum value contained in the array, if all elements can be compared. Otherwise, returns ``null``. See also :ref:`max()<class_Array_method_max>`.
.. rst-class:: classref-item-separator
@@ -1073,7 +1073,7 @@ Returns a random element from the array. Generates an error and returns ``null``
\ **Note:** Like many similar functions in the engine (such as :ref:`@GlobalScope.randi<class_@GlobalScope_method_randi>` or :ref:`shuffle<class_Array_method_shuffle>`), this method uses a common, global random seed. To get a predictable outcome from this method, see :ref:`@GlobalScope.seed<class_@GlobalScope_method_seed>`.
\ **Note:** Like many similar functions in the engine (such as :ref:`@GlobalScope.randi()<class_@GlobalScope_method_randi>` or :ref:`shuffle()<class_Array_method_shuffle>`), this method uses a common, global random seed. To get a predictable outcome from this method, see :ref:`@GlobalScope.seed()<class_@GlobalScope_method_seed>`.
.. rst-class:: classref-item-separator
@@ -1099,7 +1099,7 @@ Removes and returns the element of the array at index ``position``. If negative,
:ref:`Variant<class_Variant>` **pop_back**\ (\ ) :ref:`🔗<class_Array_method_pop_back>`
Removes and returns the last element of the array. Returns ``null`` if the array is empty, without generating an error. See also :ref:`pop_front<class_Array_method_pop_front>`.
Removes and returns the last element of the array. Returns ``null`` if the array is empty, without generating an error. See also :ref:`pop_front()<class_Array_method_pop_front>`.
.. rst-class:: classref-item-separator
@@ -1111,7 +1111,7 @@ Removes and returns the last element of the array. Returns ``null`` if the array
:ref:`Variant<class_Variant>` **pop_front**\ (\ ) :ref:`🔗<class_Array_method_pop_front>`
Removes and returns the first element of the array. Returns ``null`` if the array is empty, without generating an error. See also :ref:`pop_back<class_Array_method_pop_back>`.
Removes and returns the first element of the array. Returns ``null`` if the array is empty, without generating an error. See also :ref:`pop_back()<class_Array_method_pop_back>`.
\ **Note:** This method shifts every other element's index back, which may have a noticeable performance cost, especially on larger arrays.
@@ -1125,7 +1125,7 @@ Removes and returns the first element of the array. Returns ``null`` if the arra
|void| **push_back**\ (\ value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Array_method_push_back>`
Appends an element at the end of the array. See also :ref:`push_front<class_Array_method_push_front>`.
Appends an element at the end of the array. See also :ref:`push_front()<class_Array_method_push_front>`.
.. rst-class:: classref-item-separator
@@ -1137,7 +1137,7 @@ Appends an element at the end of the array. See also :ref:`push_front<class_Arra
|void| **push_front**\ (\ value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Array_method_push_front>`
Adds an element at the beginning of the array. See also :ref:`push_back<class_Array_method_push_back>`.
Adds an element at the beginning of the array. See also :ref:`push_back()<class_Array_method_push_back>`.
\ **Note:** This method shifts every other element's index forward, which may have a noticeable performance cost, especially on larger arrays.
@@ -1167,7 +1167,7 @@ The ``method`` takes two arguments: the current value of ``accum`` and the curre
# Same as above, but using a lambda function.
print([1, 2, 3].reduce(func(accum, number): return accum + number, 10))
If :ref:`max<class_Array_method_max>` is not desirable, this method may also be used to implement a custom comparator:
If :ref:`max()<class_Array_method_max>` is not desirable, this method may also be used to implement a custom comparator:
::
@@ -1180,7 +1180,7 @@ If :ref:`max<class_Array_method_max>` is not desirable, this method may also be
func is_length_greater(a, b):
return a.length() > b.length()
This method can also be used to count how many elements in an array satisfy a certain condition, similar to :ref:`count<class_Array_method_count>`:
This method can also be used to count how many elements in an array satisfy a certain condition, similar to :ref:`count()<class_Array_method_count>`:
::
@@ -1193,7 +1193,7 @@ This method can also be used to count how many elements in an array satisfy a ce
var even_count = arr.reduce(func(count, next): return count + 1 if is_even(next) else count, 0)
print(even_count) # Prints 2
See also :ref:`map<class_Array_method_map>`, :ref:`filter<class_Array_method_filter>`, :ref:`any<class_Array_method_any>`, and :ref:`all<class_Array_method_all>`.
See also :ref:`map()<class_Array_method_map>`, :ref:`filter()<class_Array_method_filter>`, :ref:`any()<class_Array_method_any>`, and :ref:`all()<class_Array_method_all>`.
.. rst-class:: classref-item-separator
@@ -1207,7 +1207,7 @@ See also :ref:`map<class_Array_method_map>`, :ref:`filter<class_Array_method_fil
Removes the element from the array at the given index (``position``). If the index is out of bounds, this method fails.
If you need to return the removed element, use :ref:`pop_at<class_Array_method_pop_at>`. To remove an element by value, use :ref:`erase<class_Array_method_erase>` instead.
If you need to return the removed element, use :ref:`pop_at()<class_Array_method_pop_at>`. To remove an element by value, use :ref:`erase()<class_Array_method_erase>` instead.
\ **Note:** This method shifts every element's index after ``position`` back, which may have a noticeable performance cost, especially on larger arrays.
@@ -1227,7 +1227,7 @@ Sets the array's number of elements to ``size``. If ``size`` is smaller than the
Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success, or one of the other :ref:`Error<enum_@GlobalScope_Error>` constants if this method fails.
\ **Note:** Calling this method once and assigning the new values is faster than calling :ref:`append<class_Array_method_append>` for every new element.
\ **Note:** Calling this method once and assigning the new values is faster than calling :ref:`append()<class_Array_method_append>` for every new element.
.. rst-class:: classref-item-separator
@@ -1251,7 +1251,7 @@ Reverses the order of all elements in the array.
:ref:`int<class_int>` **rfind**\ (\ what\: :ref:`Variant<class_Variant>`, from\: :ref:`int<class_int>` = -1\ ) |const| :ref:`🔗<class_Array_method_rfind>`
Returns the index of the **last** occurrence of ``what`` in this array, or ``-1`` if there are none. The search's start can be specified with ``from``, continuing to the beginning of the array. This method is the reverse of :ref:`find<class_Array_method_find>`.
Returns the index of the **last** occurrence of ``what`` in this array, or ``-1`` if there are none. The search's start can be specified with ``from``, continuing to the beginning of the array. This method is the reverse of :ref:`find()<class_Array_method_find>`.
.. rst-class:: classref-item-separator
@@ -1263,7 +1263,7 @@ Returns the index of the **last** occurrence of ``what`` in this array, or ``-1`
:ref:`int<class_int>` **rfind_custom**\ (\ method\: :ref:`Callable<class_Callable>`, from\: :ref:`int<class_int>` = -1\ ) |const| :ref:`🔗<class_Array_method_rfind_custom>`
Returns the index of the **last** element of the array that causes ``method`` to return ``true``, or ``-1`` if there are none. The search's start can be specified with ``from``, continuing to the beginning of the array. This method is the reverse of :ref:`find_custom<class_Array_method_find_custom>`.
Returns the index of the **last** element of the array that causes ``method`` to return ``true``, or ``-1`` if there are none. The search's start can be specified with ``from``, continuing to the beginning of the array. This method is the reverse of :ref:`find_custom()<class_Array_method_find_custom>`.
.. rst-class:: classref-item-separator
@@ -1289,7 +1289,7 @@ Sets the value of the element at the given ``index`` to the given ``value``. Thi
Shuffles all elements of the array in a random order.
\ **Note:** Like many similar functions in the engine (such as :ref:`@GlobalScope.randi<class_@GlobalScope_method_randi>` or :ref:`pick_random<class_Array_method_pick_random>`), this method uses a common, global random seed. To get a predictable outcome from this method, see :ref:`@GlobalScope.seed<class_@GlobalScope_method_seed>`.
\ **Note:** Like many similar functions in the engine (such as :ref:`@GlobalScope.randi()<class_@GlobalScope_method_randi>` or :ref:`pick_random()<class_Array_method_pick_random>`), this method uses a common, global random seed. To get a predictable outcome from this method, see :ref:`@GlobalScope.seed()<class_@GlobalScope_method_seed>`.
.. rst-class:: classref-item-separator
@@ -1301,7 +1301,7 @@ Shuffles all elements of the array in a random order.
:ref:`int<class_int>` **size**\ (\ ) |const| :ref:`🔗<class_Array_method_size>`
Returns the number of elements in the array. Empty arrays (``[]``) always return ``0``. See also :ref:`is_empty<class_Array_method_is_empty>`.
Returns the number of elements in the array. Empty arrays (``[]``) always return ``0``. See also :ref:`is_empty()<class_Array_method_is_empty>`.
.. rst-class:: classref-item-separator
@@ -1319,7 +1319,7 @@ If either ``begin`` or ``end`` are negative, their value is relative to the end
If ``step`` is negative, this method iterates through the array in reverse, returning a slice ordered backwards. For this to work, ``begin`` must be greater than ``end``.
If ``deep`` is ``true``, all nested **Array** and :ref:`Dictionary<class_Dictionary>` elements in the slice are duplicated from the original, recursively. See also :ref:`duplicate<class_Array_method_duplicate>`).
If ``deep`` is ``true``, all nested **Array** and :ref:`Dictionary<class_Dictionary>` elements in the slice are duplicated from the original, recursively. See also :ref:`duplicate()<class_Array_method_duplicate>`).
::
@@ -1361,7 +1361,7 @@ Sorts the array in ascending order. The final order is dependent on the "less th
\ **Note:** The sorting algorithm used is not `stable <https://en.wikipedia.org/wiki/Sorting_algorithm#Stability>`__. This means that equivalent elements (such as ``2`` and ``2.0``) may have their order changed when calling :ref:`sort<class_Array_method_sort>`.
\ **Note:** The sorting algorithm used is not `stable <https://en.wikipedia.org/wiki/Sorting_algorithm#Stability>`__. This means that equivalent elements (such as ``2`` and ``2.0``) may have their order changed when calling :ref:`sort()<class_Array_method_sort>`.
.. rst-class:: classref-item-separator
@@ -1393,7 +1393,7 @@ Sorts the array using a custom :ref:`Callable<class_Callable>`.
my_items.sort_custom(func(a, b): return a[1] > b[1])
print(my_items) # Prints [["Apple", 9], ["Tomato", 5], ["Rice", 4]]
It may also be necessary to use this method to sort strings by natural order, with :ref:`String.naturalnocasecmp_to<class_String_method_naturalnocasecmp_to>`, as in the following example:
It may also be necessary to use this method to sort strings by natural order, with :ref:`String.naturalnocasecmp_to()<class_String_method_naturalnocasecmp_to>`, as in the following example:
::
@@ -1454,7 +1454,7 @@ Appends the ``right`` array to the left operand, creating a new **Array**. This
\ **Note:** For existing arrays, :ref:`append_array<class_Array_method_append_array>` is much more efficient than concatenation and assignment with the ``+=`` operator.
\ **Note:** For existing arrays, :ref:`append_array()<class_Array_method_append_array>` is much more efficient than concatenation and assignment with the ``+=`` operator.
.. rst-class:: classref-item-separator