How do I numerically sort an array?

0 favourites
  • 5 posts
From the Asset Store
A master sorting Puzzle fun and addictive puzzle game! A challenging yet relaxing game to exercise your brain!
  • An array creates a number of X elements and gets them filled with different numerical values. I'm trying to set up a for-each loop that compares the current value with the next coming element. If I can manage to compare X element 0 and 1, I could from there easily save the value of X:0 to a global variable and then transfer that value to a new insert at the back of the array. In this way I believe a single cycle of sorting could be done in order to numerically sort the values from the front in a descending order.

    How do I make an array comparison of element X:0 and X:1 where X:0 is the current value ?

    + SpeedArray: Current value

    Would a while loop be preferable and therefore rather compare only X:0 to every other X element? In that case I assume the "SpeedArray: Current value" event wouldn't work. What would I use then?

    I'm curious to see some array solutions. I'm new to the whole array concept.

  • There is a for each element condition on the array object

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • lionz Thank you for the reply.

    Yes there is a 'for each element condition' that I could possibly use for a solution. But my problem is pretty much I have no idea how to refer to the second X element in the array. I've browsed all listed array expressions but my eyes can't find an answer.

  • The second X element is X=1, there is a condition to compare X, so value = 1.

  • lionz I tried to set up my idea through a for-each loop while using your proposed X element comparison. It worked but it's hard to tell how far the cycle goes and the numerical sorting didn't turn out reliable.

    However! I played around with the array sort action and just sorted the X axis. It works great now. Primarily it sorts based on Y:0.

    Can't believe I sat all day for a solution just to realize two lines did the work.

    -> SpeedArray: Sort X axis

    -> SpeedArray: Reverse X axis

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