YoYoGames/GameMaker-HTML5

array_sort() broken on Google Chrome

Gizmo199 opened this issue · 1 comments

Recreation:

var array = [32,24,46,2,9,4,573,0];
array_sort(array, function(a, b){
	return a > b;
});
show_debug_message(array);

The above code works on Windows & Firefox but not on Google Chrome:
Capture

Your compare function is incorrect - array_sort() expects a cmp-style function, not a less-than function. Changing it to this works:

array_sort(array, function(a, b){
	return a > b ? 1 : (a < b ? -1 : 0);
});

See https://manual.yoyogames.com/GameMaker_Language/GML_Reference/Variable_Functions/array_sort.htm