Sorting an array

0 favourites
From the Asset Store
A master sorting Puzzle fun and addictive puzzle game! A challenging yet relaxing game to exercise your brain!
  • Yann has a bug in his code: at the first loop iPos from 0 to Array.Width - 1 it's actually Array.Width - 2, otherwise it always replaces the max value with 0 and after more sorts the array has only 0's in it.

  • Je Fawk, you found a very old post. C2 now has "Array Sort" action which you can use to sort a 2D array.

  • yeah you're right, but at that time, in 2012, C2 didn't have bidirectional for loops, so the inner for loop was automagically skipped in the last iteration of the outer one, like in the wikipedia algorithm.

    But because for loops are now bidirectional, since I don't know when, it does a for "i" from 10 to 9 instead of just skipping.

    Good catch, I'll try to reupload a correction soon.

  • dop2000 i replied because i can't use/don't know how to use the sort they have implemented so i'm making my own

    I got an array of 3 x ?? x 1, the height changes with the number of players and i'm trying to sort by score but yeah... their sort ... ???

    [Number] [PlayerName] [Score]

    So I'm stuck with making it myself

    Yann sorry, i didn't know there was a change in how loops worked before

  • Hey !

    Here's what the manual states about the Sort action:

    Sort

    Sorts the order of elements on an axis in ascending order. Note that in multidimensional arrays this sorts based on the first element on the axis. For example sorting the X axis in a 2D array will sort the order of the columns based on the elements at Y co-ordinate 0, while preserving the contents of each column.

    So, if you want to sort by score, just change the order of columns in your array. Also, I'd suggest you make your array ?? x 3 x 1...

    Hope this helps. Cheers!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • brunopalermo i checked the doc and tried implementing it but really it does look like random stuff even with a 2d array :/

  • Here's an working example, !

    https://www.dropbox.com/s/dcb5cmvwqo1ue ... .capx?dl=1

    Feel free to ask if you need further assistance! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    Cheers!

  • Wow that was so easy god dammit!

    Thanks a lot brunopalermo !

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