diff options
Diffstat (limited to 'doc/classes/Array.xml')
-rw-r--r-- | doc/classes/Array.xml | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 275b217247..d505ee98cc 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -194,7 +194,7 @@ <return type="void" /> <argument index="0" name="value" type="Variant" /> <description> - Removes the first occurrence of a value from the array. To remove an element by index, use [method remove] instead. + Removes the first occurrence of a value from the array. To remove an element by index, use [method remove_at] 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> @@ -400,7 +400,7 @@ [/codeblock] </description> </method> - <method name="remove"> + <method name="remove_at"> <return type="void" /> <argument index="0" name="position" type="int" /> <description> @@ -477,15 +477,19 @@ [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] - class MyCustomSorter: - static func sort_ascending(a, b): - if a[0] < b[0]: - return true - return false + func sort_ascending(a, b): + if a[0] < b[0]: + return true + return false - var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]] - my_items.sort_custom(MyCustomSorter.sort_ascending) - print(my_items) # Prints [[4, Tomato], [5, Potato], [9, Rice]]. + func _ready(): + var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]] + my_items.sort_custom(sort_ascending) + print(my_items) # Prints [[4, Tomato], [5, Potato], [9, Rice]]. + + # Descending, lambda version. + my_items.sort_custom(func(a, b): return a[0] > b[0]) + print(my_items) # Prints [[9, Rice], [5, Potato], [4, Tomato]]. [/gdscript] [csharp] // There is no custom sort support for Godot.Collections.Array |