ZombieSquirrel
Member
I've been at this for hours now and can't figure this out, and not gettinng a working answer
I need to sort a grid in an ascending order.
The grid has 3 columns: an instance name, an instance y value, and an instance x value.
I'm doing this to have my own depth system.
Now, I definitely have to order the grid for the y values,
which is a quick
ds_grid_sort(grid, row, true)
but... some y values are the same! For those, I need to give priority to instances with a larger (or smaller) x value.
Let's say 2 instances are right next to each other, in this way, the left instance will always have priority over the right one, but this can only be done if I sort the x values as well, at least for those instances with the same y value.
A quick example:
row y row x
1 1
2 2
5 3
3 4
2 5
becomes (after sorting y)
row y row x
1 1
2 2
2 5
3 4
5 3
OR it becomes
row y row x
1 1
2 5
2 2
3 4
5 3
Notice the region where the y's are 2.
I need to make sure they always get ordered in just the one possibility:
2 2
2 5
(smaller x value gets priority)
So in order to do this, I'd need to define the region where the y values, after being sorted, are the same. Then I need to sort that region only while leaving the rest of the sorted grid intact.
Anyone have an idea?
I've been told to sort x first, then y, and I get the logic behind that, but this just does not work...
It might have to do with that my player is part of this grid, so the player's x and y wil cause this grid to constantly update according to the player's movement.
Somehow I think it can't be this difficult to just have a bunch of instances that, when one's y is lower than the other, the second gets drawn on top. If one's y is the same, the left one gets drawn first.
I've been told Game Maker is good for concepts, but if you want to make a real game to just go Unity. I refuse that. I have a simple concept, but this is quite essential and I'm baffled that there's no function that does something like
ds_grid_sort_multiple or something, where you sort one row first, keep that row sorted, then evaluate those numbers that are the same, then sort them according to a second row of numbers…
If there is a solution, i need exact code, like what kind of functions do i follow up on each other?
I need to sort a grid in an ascending order.
The grid has 3 columns: an instance name, an instance y value, and an instance x value.
I'm doing this to have my own depth system.
Now, I definitely have to order the grid for the y values,
which is a quick
ds_grid_sort(grid, row, true)
but... some y values are the same! For those, I need to give priority to instances with a larger (or smaller) x value.
Let's say 2 instances are right next to each other, in this way, the left instance will always have priority over the right one, but this can only be done if I sort the x values as well, at least for those instances with the same y value.
A quick example:
row y row x
1 1
2 2
5 3
3 4
2 5
becomes (after sorting y)
row y row x
1 1
2 2
2 5
3 4
5 3
OR it becomes
row y row x
1 1
2 5
2 2
3 4
5 3
Notice the region where the y's are 2.
I need to make sure they always get ordered in just the one possibility:
2 2
2 5
(smaller x value gets priority)
So in order to do this, I'd need to define the region where the y values, after being sorted, are the same. Then I need to sort that region only while leaving the rest of the sorted grid intact.
Anyone have an idea?
I've been told to sort x first, then y, and I get the logic behind that, but this just does not work...
It might have to do with that my player is part of this grid, so the player's x and y wil cause this grid to constantly update according to the player's movement.
Somehow I think it can't be this difficult to just have a bunch of instances that, when one's y is lower than the other, the second gets drawn on top. If one's y is the same, the left one gets drawn first.
I've been told Game Maker is good for concepts, but if you want to make a real game to just go Unity. I refuse that. I have a simple concept, but this is quite essential and I'm baffled that there's no function that does something like
ds_grid_sort_multiple or something, where you sort one row first, keep that row sorted, then evaluate those numbers that are the same, then sort them according to a second row of numbers…
If there is a solution, i need exact code, like what kind of functions do i follow up on each other?