Use sort_custom
of Array
. Here's an example:
class MyCustomSorter:
static func sort(a, b):
if typeof(b)==TYPE_STRING || (typeof(a)!=TYPE_STRING && typeof(b)!=TYPE_STRING && a<b):
return true
return false
func _ready():
var my_items = ["",11,1,"",4]
my_items.sort_custom(MyCustomSorter, "sort")
printt(my_items)
The sort function has to return true if the first element is less than the second one and has to be swapped or false otherwise.