diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-02-05 09:30:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 09:30:19 +0100 |
commit | d93f75fae5766c029af9eb28b7a5593d96f66750 (patch) | |
tree | 500bb716de953327f48a2fa984417e6d7dd483f6 /doc/classes | |
parent | a7a51fb3261d4d239dcce3070cbdbdb8e3abdcdb (diff) | |
parent | fb83d905daed6c2a7c4f95712d47815c7ccd8f2e (diff) |
Merge pull request #45698 from KoBeWi/callables_are_love_callables_are_life
Change sort_custom/bsearch_custom to use Callables
Diffstat (limited to 'doc/classes')
-rw-r--r-- | doc/classes/Array.xml | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index de3d89ee0f..cea5360234 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -191,11 +191,9 @@ </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. @@ -537,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] @@ -553,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] |