A simple multi-column sort for a 2D array

Discussion and feedback on Construct 2

Post » Thu Jul 10, 2014 4:04 pm

I worked out a fairly simple routine for sorting a two-dimensional array by multiple columns (first by D, then by A, etc). It leverages Array.Sort to do the heavy lifting, so it's just a matter of moving the data around to the right places. I couldn't find any examples of this, so I thought I'd share it in case anybody else is searching. :)

It looks something like this:


Some caveats:

    Arrange the Sort_Column() calls in reverse order of priority.

    Array.Sort reverses previous ordering, so you might have to change your "Ascending" or "Descending" to the opposite of what you'd expect, depending on the sorting that happens after that call.

    Be sure to include the "Ascending" parameter even though it's the default. If you don't, a "Descending" entry from a previous call could be lingering in the Function object which would give the wrong direction.

I hope this is useful! If you have any questions or improvements, just let me know. :)

Example attached!
You do not have the required permissions to view the files attached to this post.
Posts: 55
Reputation: 616

Post » Thu Mar 05, 2015 1:02 am

The example help me very much... Thank you :mrgreen:
Posts: 32
Reputation: 5,876

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 0 guests