godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.09k stars 21.18k forks source link

GDScript- Array.short_custom fails passing a class after #22737 #22952

Closed Ranoller closed 6 years ago

Ranoller commented 6 years ago

Godot version:

cff89fc4e4f2ceb577b5f7a119d98cb22d41ea44

OS/device including version:

Win 7

Issue description:

After this commit: https://github.com/godotengine/godot/pull/22737 Godot can´t short an array with the system described in the documentation, a.k.a:

void sort_custom ( Object obj, String func ) Sort the array using a custom method and return reference to the array. 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 true if the first argument is less than the second, and return false otherwise. Note: you cannot randomize the return value as the heapsort algorithm expects a deterministic result. Doing so will result in unexpected behavior.

class MyCustomSorter: static func sort(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")

Error is in new line 261 in core/array.cpp and return exactly the error that this line introduce (*this).

Ranoller commented 6 years ago

Sorry... i didn´t see #22833. Closing.