How do I sorting array X axis with it's Y axises?

0 favourites
  • 7 posts
From the Asset Store
It's here!
$4.95 USD
Creepy and nasty horror track. It's terrifying from the beginning till the end. Goosebumps guaranteed
  • I have a 100 x 9 x 1 array.

    X axis indicates 'UID' of objects.

    Y axises indicate distance, HP, size, velocity, ETC...

    in X axis, 'sort X axis' event works well. but problem is Y axises.

    I want to sort X axis by values of Y axises.

    So if I click HP button list should sort by order of HP....

    Is it possible?

    or should I try something else?

  • [quote:1exxm20z]X axis indicates 'UID' of objects.

    So do you actually store UIDs in the array or do you use UID as an index for X axis?

    For example when you do Array Set At(5,0) to 99 - does it mean that UID of the 5th object's is 99, or does it mean that object with UID=5 has HP=99?

    If you use UID as X-index and don't actually store it in the array, then you can't sort it!

    If you do store UID in the array, you can swap columns 0 and 1 and sort, then swap them back.

    Here is a demo:

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

    For other methods, see this post:

    viewtopic.php?f=147&t=67745

    Also, why do you need this array anyway? In C2 many things you normally would do with arrays, can be done much easier without them!

    You can store all these values (HP, size etc) in instance variables. And then you can sort them any way you like using "System->For each (ordered)" and similar events.

  • I have a 100 x 9 x 1 array.

    X axis indicates 'UID' of objects.

    Y axises indicate distance, HP, size, velocity, ETC...

    in X axis, 'sort X axis' event works well. but problem is Y axises.

    I want to sort X axis by values of Y axises.

    So if I click HP button list should sort by order of HP....

    Is it possible?

    or should I try something else?

    I checked and it might be able to work so look into this... go into the array options and go to compare at xy

    you get to compare the two values and then in the add actions part, you can set the x. looks like you can set at X and In the value part set at whatever your array is called .CurY not sure if that will work or not lol but might get you close. Good luck!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [quote:aautvm8u]X axis indicates 'UID' of objects.

    So do you actually store UIDs in the array or do you use UID as an index for X axis?

    For example when you do Array Set At(5,0) to 99 - does it mean that UID of the 5th object's is 99, or does it mean that object with UID=5 has HP=99?

    If you use UID as X-index and don't actually store it in the array, then you can't sort it!

    If you do store UID in the array, you can swap columns 0 and 1 and sort, then swap them back.

    Here is a demo:

    dropbox.com/s/88wse8qyrr3ys ... .capx?dl=0

    For other methods, see this post:

    viewtopic.php?f=147&t=67745

    Also, why do you need this array anyway? In C2 many things you normally would do with arrays, can be done much easier without them!

    You can store all these values (HP, size etc) in instance variables. And then you can sort them any way you like using "System->For each (ordered)" and similar events.

    Thank you but I think this is not what i meant.

    For example, there is a list like this.

    X axis(UID) / Y1(HP), Y2(DISTANCE), Y3(SIZE) ...

    125 / 100,421,1024

    84 / 125,552,512

    62 / 625,126,256

    If I sort X axis in this array, it should looks like this.

    62 / 625,126,256

    84 / 125,552,512

    125 / 100,421,1024

    And I would like to these kind of array sorting.

    (Order by HP)

    125 / 100,421,1024

    84 / 125,552,512

    62 / 625,126,256

    (Order by DISTANCE)

    62 / 625,126,256

    125 / 100,421,1024

    84 / 125,552,512

    (Order by SIZE)

    62 / 625,126,256

    84 / 125,552,512

    125 / 100,421,1024

  • So UID is in Y0?

    When you set value at axis X in 2D-array, you actually set it at 0 index on Y axis.

    So "Set value at (X=2) to 99" is the same as "Set value at (X=2, Y=0) to 99"

    Have you tried my demo capx? It does exactly what you want.

    And also consider doing this without the array. Since you are dealing with instances and UIDs, you should be able do all this easier if you use instance variables.

  • oh... ok. i'll look into it more.

  • Thanks. Problem solved perfectly with your solution.

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