Discord
Login
Community
DARK THEME

List sorting

how does the list.sortList(func) work? i'm trying to sort a list of objects by their y level and another variable so that I can draw them at the right depth

Basically, a list sorting function is calling a specific type of function, where the returned value determines weather a value moves up or down. So, you would define a function like this.

sortingFunc = function(point1,point2)
  return point1.y - point2.y
end

List.sortList(sortingFunc)

Basically what Micro Studio is doing is a compare function. If the returned value is positive, point1 moves up, if the returned value us negative, then point2 moves up. You can also shrink the function to only one line, but I wouldent really reccommend doing it, it's a little tricky.

List.sortList(function(point1,point2) point2.y-point2.y end)

thank you, this will help a lot

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community