Sort arrays based on each column or row

Get help using Construct 2

Post » Sun Jun 25, 2017 9:12 am

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[i].posic = 0;
for (j = 0; j < 8; j++)
{
if (Array[i].pt < Array[j].pt and i != j)
{
Array[i].posic -= 1;
}
if (Array[i].pt == Array[j].pt and i != j)
{
if (Array[i].gfor - Array[i].gagainst < Array[j].gfor - Array[j].gagainst and i != j)
{
Array[i].posic -= 1;
}
}
}
}
B
20
S
10
G
2
Posts: 56
Reputation: 2,762

Post » Fri Aug 11, 2017 1:33 am

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.
B
17
S
6
G
1
Posts: 41
Reputation: 1,725

Post » Fri Aug 11, 2017 11:04 am

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Aug 13, 2017 3:48 am

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 ).
B
20
S
10
G
2
Posts: 56
Reputation: 2,762


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests