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.xml32
1 files changed, 19 insertions, 13 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml
index e09c1f4b08..08455bb7bc 100644
--- a/doc/classes/Array.xml
+++ b/doc/classes/Array.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="Array" category="Built-In Types" version="3.2">
+<class name="Array" version="4.0">
<brief_description>
Generic array datatype.
</brief_description>
@@ -8,11 +8,11 @@
[b]Example:[/b]
[codeblock]
var array = ["One", 2, 3, "Four"]
- print(array[0]) # One
- print(array[2]) # 3
- print(array[-1]) # Four
+ print(array[0]) # One.
+ print(array[2]) # 3.
+ print(array[-1]) # Four.
array[2] = "Three"
- print(array[-2]) # Three
+ print(array[-2]) # Three.
[/codeblock]
Arrays are always passed by reference.
</description>
@@ -93,7 +93,7 @@
<return type="Variant">
</return>
<description>
- Returns the last element of the array if the array is not empty.
+ Returns the last element of the array, or [code]null[/code] if the array is empty.
</description>
</method>
<method name="bsearch">
@@ -186,7 +186,7 @@
<return type="Variant">
</return>
<description>
- Returns the first element of the array if the array is not empty.
+ Returns the first element of the array, or [code]null[/code] if the array is empty.
</description>
</method>
<method name="has">
@@ -243,14 +243,14 @@
<return type="Variant">
</return>
<description>
- Removes the last element of the array.
+ Removes and returns the last element of the array. Returns [code]null[/code] if the array is empty.
</description>
</method>
<method name="pop_front">
<return type="Variant">
</return>
<description>
- Removes the first element of the array.
+ Removes and returns the first element of the array. Returns [code]null[/code] if the array is empty.
</description>
</method>
<method name="push_back">
@@ -322,7 +322,12 @@
<method name="sort">
<description>
Sorts the array.
- [b]Note:[/b] strings are sorted in alphabetical, not natural order.
+ [b]Note:[/b] Strings are sorted in alphabetical order (as opposed to natural order). This may lead to unexpected behavior when sorting an array of strings ending with a sequence of numbers. Consider the following example:
+ [codeblock]
+ var strings = ["string1", "string2", "string10", "string11"]
+ strings.sort()
+ print(strings) # Prints [string1, string10, string11, string2]
+ [/codeblock]
</description>
</method>
<method name="sort_custom">
@@ -331,17 +336,18 @@
<argument index="1" name="func" type="String">
</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 [code]true[/code] if the first argument is less than the second, and return [code]false[/code] otherwise.
+ 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].
[b]Note:[/b] you cannot randomize the return value as the heapsort algorithm expects a deterministic result. Doing so will result in unexpected behavior.
[codeblock]
class MyCustomSorter:
- static func sort(a, b):
+ static func sort_ascending(a, b):
if a[0] &lt; b[0]:
return true
return false
var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]]
- my_items.sort_custom(MyCustomSorter, "sort")
+ my_items.sort_custom(MyCustomSorter, "sort_ascending")
+ print(my_items) # Prints [[4, Tomato], [5, Potato], [9, Rice]].
[/codeblock]
</description>
</method>