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

Get help using Construct 2

Post » Fri Sep 19, 2014 3:29 pm

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.
B
9
S
1
Posts: 22
Reputation: 946

Post » Fri Sep 19, 2014 4:14 pm

Meanwhile I found this post: how-do-i-sort-json-data_t115247

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.

Regards.
B
9
S
1
Posts: 22
Reputation: 946

Post » Fri Sep 19, 2014 4:52 pm

Here's some custom bubble sorting made through events. You can sort any column in ascending or descending order.
You do not have the required permissions to view the files attached to this post.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Fri Sep 19, 2014 4:53 pm

Thanks alot Magistross ! Going to check it out !!
B
9
S
1
Posts: 22
Reputation: 946



Return to How do I....?

Who is online

Users browsing this forum: 25games, Artcadev, brunopalermo, MaxxMunnn, mcscooter, Soluna Software and 24 guests