summaryrefslogtreecommitdiff
path: root/doc/classes/Array.xml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/classes/Array.xml')
-rw-r--r--doc/classes/Array.xml81
1 files changed, 43 insertions, 38 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml
index db5d377c62..54bbe7a94b 100644
--- a/doc/classes/Array.xml
+++ b/doc/classes/Array.xml
@@ -166,7 +166,7 @@
[/codeblock]
</description>
</method>
- <method name="back">
+ <method name="back" qualifiers="const">
<return type="Variant">
</return>
<description>
@@ -191,15 +191,13 @@
</return>
<argument index="0" name="value" type="Variant">
</argument>
- <argument index="1" name="obj" type="Object">
+ <argument index="1" name="func" type="Callable">
</argument>
- <argument index="2" name="func" type="StringName">
- </argument>
- <argument index="3" name="before" type="bool" default="true">
+ <argument index="2" name="before" type="bool" default="true">
</argument>
<description>
Finds the index of an existing value (or the insertion index that maintains sorting order, if the value is not yet present in the array) using binary search and a custom comparison method. Optionally, a [code]before[/code] specifier can be passed. If [code]false[/code], the returned index comes after all existing entries of the value in the array. The custom method receives two arguments (an element from the array and the value searched for) and must return [code]true[/code] if the first argument is less than the second, and return [code]false[/code] otherwise.
- [b]Note:[/b] Calling [method bsearch] on an unsorted array results in unexpected behavior.
+ [b]Note:[/b] Calling [method bsearch_custom] on an unsorted array results in unexpected behavior.
</description>
</method>
<method name="clear">
@@ -209,7 +207,7 @@
Clears the array. This is equivalent to using [method resize] with a size of [code]0[/code].
</description>
</method>
- <method name="count">
+ <method name="count" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="value" type="Variant">
@@ -218,7 +216,7 @@
Returns the number of times an element is in the array.
</description>
</method>
- <method name="duplicate">
+ <method name="duplicate" qualifiers="const">
<return type="Array">
</return>
<argument index="0" name="deep" type="bool" default="false">
@@ -234,10 +232,12 @@
<argument index="0" name="value" type="Variant">
</argument>
<description>
- Removes the first occurrence of a value from the array.
+ Removes the first occurrence of a value from the array. To remove an element by index, use [method remove] instead.
+ [b]Note:[/b] This method acts in-place and doesn't return a value.
+ [b]Note:[/b] On large arrays, this method will be slower if the removed element is close to the beginning of the array (index 0). This is because all elements placed after the removed element have to be reindexed.
</description>
</method>
- <method name="find">
+ <method name="find" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="what" type="Variant">
@@ -248,7 +248,7 @@
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed.
</description>
</method>
- <method name="find_last">
+ <method name="find_last" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="value" type="Variant">
@@ -257,7 +257,7 @@
Searches the array in reverse order for a value and returns its index or [code]-1[/code] if not found.
</description>
</method>
- <method name="front">
+ <method name="front" qualifiers="const">
<return type="Variant">
</return>
<description>
@@ -265,7 +265,7 @@
[b]Note:[/b] Calling this function is not the same as writing [code]array[0][/code]. If the array is empty, accessing by index will pause project execution when running from the editor.
</description>
</method>
- <method name="has">
+ <method name="has" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="value" type="Variant">
@@ -307,11 +307,12 @@
[/codeblocks]
</description>
</method>
- <method name="hash">
+ <method name="hash" qualifiers="const">
<return type="int">
</return>
<description>
- Returns a hashed integer value representing the array contents.
+ Returns a hashed integer value representing the array and its contents.
+ [b]Note:[/b] Arrays with equal contents can still produce different hashes. Only the exact same arrays will produce the same hashed integer value.
</description>
</method>
<method name="insert">
@@ -323,30 +324,25 @@
</argument>
<description>
Inserts a new element at a given position in the array. The position must be valid, or at the end of the array ([code]pos == size()[/code]).
+ [b]Note:[/b] This method acts in-place and doesn't return a value.
+ [b]Note:[/b] On large arrays, this method will be slower if the inserted element is close to the beginning of the array (index 0). This is because all elements placed after the newly inserted element have to be reindexed.
</description>
</method>
- <method name="invert">
- <return type="void">
- </return>
- <description>
- Reverses the order of the elements in the array.
- </description>
- </method>
- <method name="is_empty">
+ <method name="is_empty" qualifiers="const">
<return type="bool">
</return>
<description>
Returns [code]true[/code] if the array is empty.
</description>
</method>
- <method name="max">
+ <method name="max" qualifiers="const">
<return type="Variant">
</return>
<description>
Returns the maximum value contained in the array if all elements are of comparable types. If the elements can't be compared, [code]null[/code] is returned.
</description>
</method>
- <method name="min">
+ <method name="min" qualifiers="const">
<return type="Variant">
</return>
<description>
@@ -421,14 +417,15 @@
<return type="Variant">
</return>
<description>
- Removes and returns the last element of the array. Returns [code]null[/code] if the array is empty, without printing an error message.
+ Removes and returns the last element of the array. Returns [code]null[/code] if the array is empty, without printing an error message. See also [method pop_front].
</description>
</method>
<method name="pop_front">
<return type="Variant">
</return>
<description>
- Removes and returns the first element of the array. Returns [code]null[/code] if the array is empty, without printing an error message.
+ Removes and returns the first element of the array. Returns [code]null[/code] if the array is empty, without printing an error message. See also [method pop_back].
+ [b]Note:[/b] On large arrays, this method is much slower than [method pop_back] as it will reindex all the array's elements every time it's called. The larger the array, the slower [method pop_front] will be.
</description>
</method>
<method name="push_back">
@@ -437,7 +434,7 @@
<argument index="0" name="value" type="Variant">
</argument>
<description>
- Appends an element at the end of the array.
+ Appends an element at the end of the array. See also [method push_front].
</description>
</method>
<method name="push_front">
@@ -446,7 +443,8 @@
<argument index="0" name="value" type="Variant">
</argument>
<description>
- Adds an element at the beginning of the array.
+ Adds an element at the beginning of the array. See also [method push_back].
+ [b]Note:[/b] On large arrays, this method is much slower than [method push_back] as it will reindex all the array's elements every time it's called. The larger the array, the slower [method push_front] will be.
</description>
</method>
<method name="remove">
@@ -455,7 +453,9 @@
<argument index="0" name="position" type="int">
</argument>
<description>
- Removes an element from the array by index. If the index does not exist in the array, nothing happens.
+ Removes an element from the array by index. If the index does not exist in the array, nothing happens. To remove an element by searching for its value, use [method erase] instead.
+ [b]Note:[/b] This method acts in-place and doesn't return a value.
+ [b]Note:[/b] On large arrays, this method will be slower if the removed element is close to the beginning of the array (index 0). This is because all elements placed after the removed element have to be reindexed.
</description>
</method>
<method name="resize">
@@ -467,7 +467,14 @@
Resizes the array to contain a different number of elements. If the array size is smaller, elements are cleared, if bigger, new elements are [code]null[/code].
</description>
</method>
- <method name="rfind">
+ <method name="reverse">
+ <return type="void">
+ </return>
+ <description>
+ Reverses the order of the elements in the array.
+ </description>
+ </method>
+ <method name="rfind" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="what" type="Variant">
@@ -485,14 +492,14 @@
Shuffles the array such that the items will have a random order. This method uses the global random number generator common to methods such as [method @GlobalScope.randi]. Call [method @GlobalScope.randomize] to ensure that a new seed will be used each time if you want non-reproducible shuffling.
</description>
</method>
- <method name="size">
+ <method name="size" qualifiers="const">
<return type="int">
</return>
<description>
Returns the number of elements in the array.
</description>
</method>
- <method name="slice">
+ <method name="slice" qualifiers="const">
<return type="Array">
</return>
<argument index="0" name="begin" type="int">
@@ -528,12 +535,10 @@
<method name="sort_custom">
<return type="void">
</return>
- <argument index="0" name="obj" type="Object">
- </argument>
- <argument index="1" name="func" type="StringName">
+ <argument index="0" name="func" type="Callable">
</argument>
<description>
- Sorts the array using a custom method. The arguments are an object that holds the method and the name of such method. The custom method receives two arguments (a pair of elements from the array) and must return either [code]true[/code] or [code]false[/code].
+ Sorts the array using a custom method. The custom method receives two arguments (a pair of elements from the array) and must return either [code]true[/code] or [code]false[/code].
[b]Note:[/b] you cannot randomize the return value as the heapsort algorithm expects a deterministic result. Doing so will result in unexpected behavior.
[codeblocks]
[gdscript]
@@ -544,7 +549,7 @@
return false
var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]]
- my_items.sort_custom(MyCustomSorter, "sort_ascending")
+ my_items.sort_custom(MyCustomSorter.sort_ascending)
print(my_items) # Prints [[4, Tomato], [5, Potato], [9, Rice]].
[/gdscript]
[csharp]