0 Favourites

How sorting in xyz works ?

  • 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

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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.

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

  • 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

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