How sorting in xyz works ?

Get help using Construct 2

Post » Sun Apr 05, 2015 1:32 pm

Hello guys,
cant get the idea of sort/reverse mechanics in xyz array.
As I understand, every single value in X axis (width) contains pack of Y values defined by "height" in properties. And, similarily, every single value in Y axis contains number of Z values (depth)

So, this table for:
3 players - gos to x axis
each player has 1 score (3player + 3 score=6 values) - goes to y axis
each score has 1 subscore (9 values altogether) - goes to z axis.
In this file:
dropbox.com/s/swcpnsi8n13dw59/array2.capx?dl=0

after series of sorting and resorting on different axises some values go to Universe , ending up with zeroes :shock:
B
10
S
3
Posts: 25
Reputation: 709

Post » Sun Apr 05, 2015 2:06 pm

You have 9 text fields for a 3*2*2 array which consequently has 12 values (3*2*2 = 18), so of course you end up with some zeroes after sorting.

Took your example with a 3*2*2 array, now you can check how the sorting works:
https://copy.com/qJZNymdD2Msddxxt

hint: it's complicated, even more so with empty values, I suggest not doing it, instead just looking at the right places via loops to fetch the values, and if you have to do some sorting, just add all values to a one- or twodimensional array and do the sorting there.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sun Apr 05, 2015 2:36 pm

thanks mindfaQ!!!
So your suggestion is to have one text value i.e. "score" for every player in form of score|subscore
and retrieve it with tokenat ?
B
10
S
3
Posts: 25
Reputation: 709

Post » Sun Apr 05, 2015 3:10 pm

Not necessarily. You can use arrays to store the information, just make sure that you don't sort that array, because it will screw up its structure, especially when it is a 3d array.

Instead when you want to read the values for every player, that then you want to have sorted, you could use a loop like (in this examples 3 players):
player 1 has a best time of 190 sec at level 9
player 2 has best time of 200 sec at level 9
player 3 has a best time of 150 sec at level 9

level = 9
timerank = 1

set size sortarray (0,2,1)
for 1 to 3:
push to sortarray array.at(loopindex-1, level-1, timerank-1)
set sortarray at (loopindex-1, 1) to "Player "&loopindex

after that you can sort by x and end up with an array like:
150, Player 3
190, Player 1
200, Player 2

... and can work with that.

Of course you can also work with a dictionary and loops, this would reduce wasted space, as you won't have empty values. Keys could be named like "p1s1t2" (player 1, score 1, time 2) and you could use while loops to retrieve stuff, again top example:


sortarray set size 0,2,1
localvariable: counter = 1
while
dictionary has key "p"&str(counter)&"s"&str(level)&t&str(timerank) [you don't necessarily need the str(), construct is smart enough to auto-convert]
counter < maxplayernumber [infinite loops should not be able to happen with this]:
push sortarray dictionary.get("p"&str(counter)&"s"&str(level)&t&str(timerank))
set sortarray at (counter-1, 1) to "Player "&counter
counter +1


sort by x again and you'll end up with the same again:
150, Player 3
190, Player 1
200, Player 2
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests