Sort arrays based on each column or row

0 favourites
  • 4 posts
From the Asset Store
Match the rows with tofus to clear the rows before you pass the cook.
  • Maybe I am missing something obvious here, but although I can do it by using multiple arrays, wondering if there is a solution that would let me use a single multidimensional array for this: In flash it is very easy, in construct I can apparently only sort X, Y and Z, In flash I can sort it any way I want, by specific column in Y for example.

    Anyway this is what it would look like in Flash using multidimensional arrays:

    Create array like this for each team : Array.push({name:teamA, rank:6, score:0, power:6, win:0, dr:0, lose:0, pt:0, gfor:0, gagainst:0, gd:0, posic:0});

    In Flash I can sort based on any of those, name, rank, power, score, goals, etc.....

    Then with code below do what I need to do. Sort by total points, and if points are equal between teams, sort those by goal differential, so teams with better goal differential come on top. With a single array in Construct 2 simple enough to sort team standings by total points, but not by goal differential because it will not sort points and goal differential values independently ( both stored in Y columns )

    for (i = 0; i < 8; i++)

    {

    Array.posic = 0;

    for (j = 0; j < 8; j++)

    {

    if (Array.pt < Array[j].pt and i != j)

    {

    Array.posic -= 1;

    }

    if (Array.pt == Array[j].pt and i != j)

    {

    if (Array.gfor - Array.gagainst < Array[j].gfor - Array[j].gagainst and i != j)

    {

    Array.posic -= 1;

    }

    }

    }

    }

  • Only solution I've found is to just add a new column at the front, copy the values from the column I actually want and then sort before popping the front.

    I'd love to know if there's a better way.

  • Since ....

    1/ C2 is marketed as "You can now make advanced games without writing a line of code. Construct 2 does the hard work so you don't have to."

    2/ I belong to the targeted category of 'scripters'.

    3/ I can only trust (because of point 1) that i can never ever reach the performance of the build in Array sort algorithm. And (because of point 2) i am not supposed to have the knowledge to beat that performance.

    ....... i use this lazy method. Basically it comes down to reserving the X-axis for sorting by self-made 'filters', and store every value on the Y-axis.

    https://www.dropbox.com/s/brvmx9pupif37 ... .capx?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, I will check it out. I will need it soon. I kind of stopped and concentrated on other stuff ( always seems like working on at least 4-5 games at the same time ).

    I think with construct it's a matter of wrapping one's head around its way of working. 90% of the time it is easy, but the other 10% seems like it would be easier if you could just script it the old fashioned way ( which may not be true, but it appears that way to me ).

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