A simple multi-column sort for a 2D array

0 favourites
  • 2 posts
From the Asset Store
Buildings - Isometric view - PNG transparent - multi styles, multi fonctions buildings
  • 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:

    [attachment=1:1oxs8f6h][/attachment:1oxs8f6h]

    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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The example help me very much... Thank you

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)