Array Quest: How can I order an array by some column ?

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hello guys !

    I already searched the forum for a direct answer and found alot of capx files with some algorihtms with FOR loops to "bubble sort" an array. Nevertheless I didn't find any straight answer...

    Imagine I have an ARRAY object with WIDTH=10 and HEIGHT=4.

    Assume that the 4 HEIGHT elements are my columns.

    Isn't there any function in Construct so I can order my ARRAY, regarding for instante the last HEIGHT element? (in this case assuming the elements are from 0 to 3 , I wan't to order by the last element with the index of 3).

    Example: "order by the column D - index element number 3 of Y elements of the array"

    Unordered ------Ordered

    A B C D-------------A B C D

    1 1 1 3--------------1 1 1 4

    2 2 2 2--------------1 1 1 3

    1 1 1 4--------------2 2 2 2

    If there was to be any SQL alike in Construct it would be something in this lines:

    "SELECT * FROM array_table ORDER BY column_with_index_3 DESC;" ... and assing the SELECT results to the same or another array.

    So any ideias how can I order this array ?

    Thank you very much guys !

    Best Regards.

  • Meanwhile I found this post:

    If one uses the 1st column as the index to order the it works by sorting X and if you wan't an highscore reversing the X axis.

    Anyway this works but I think Construct is a great and very well made product. This kind of matrix manipulation as I specified earlier should be native to Construct.... I guess in the form of queries would also be a great add-on for this kind of manipulation.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here's some custom bubble sorting made through events. You can sort any column in ascending or descending order.

  • Thanks alot Magistross ! Going to check it out !!

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