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

0 favourites
  • 6 posts
From the Asset Store
amazing template of the game of ordering colors with strings made with construct3 (requires c3 license) optimized with j
  • 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

  • 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'

  • 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...

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Solved already! Thanks!

  • Josek what was your solution?

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