# How do I sort a bidimensional array by one column [Solved]

Get help using Construct 2

### » Mon Feb 06, 2017 7:10 pm

Hi everyone!

I'm trying to sort a kind of "big" C2 bidimensional array with 6 x cells and dynamic y cells like:

150, cell01, cell02, cell03, cell04, cell05
50, cell11, cell12, cell13, cell14, cell15
300, cell21, cell22, cell23, cell24, cell25
...

I want to sort it ascending by the first number of each row like:

50, cell11, cell12, cell13, cell14, cell15
150, cell01, cell02, cell03, cell04, cell05
300, cell21, cell22, cell23, cell24, cell25
...

Can someone brings me some help? Thanks
Last edited by Josek5494 on Tue Feb 07, 2017 12:14 pm, edited 1 time in total.
B
20
S
6
G
2
Posts: 260
Reputation: 2,678

### » Mon Feb 06, 2017 7:30 pm

If you use the 'Sort' action on the array, it will sort by whatever is in the first column - so you should be able to go ahead and use 'Sort'
B
26
S
7
Posts: 254
Reputation: 2,389

### » Mon Feb 06, 2017 7:37 pm

mrtumbles wrote:If you use the 'Sort' action on the array, it will sort by whatever is in the first column - so you should be able to go ahead and use 'Sort'

I tried it, selecting Y, but it sorts all the columns separately for me and takes all the information on the rows out of it place...
B
20
S
6
G
2
Posts: 260
Reputation: 2,678

### » Mon Feb 06, 2017 9:16 pm

Uh, no. You want to sort on X. Y is kinda 'attached' to X. As branches on a tree. Why i visualise an array as a tree. Sorting on the Y will indeed rearrange the whole tree, forgetting the branches.

I would Use an temp array. (in dont know better)

For the first number (150 in '150, cell01, cell02, cell03, cell04, cell05') you can just sort on the X-axis.

Then you got to loop each Y on an each X index, copy the values on that Y index to an X-axis in a temp array.
Sort that array, and copy them back.

So copy 'cell01, cell02, cell03, cell04, cell05' to a temp array. Sort the Temp on X. Copy the sorted values back.

If you need an example, give me an array in a .capx. Will do.
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Tue Feb 07, 2017 12:14 pm

B
20
S
6
G
2
Posts: 260
Reputation: 2,678

### » Wed Apr 26, 2017 4:11 am

B
31
S
12
G
2
Posts: 49
Reputation: 3,177