How to sort array that contains structures?

Hello!
Does someone know why this doesn’t work?
Some of the structs switched with this Bubble Sort are resetted to 0…
I’m trying to sort an array that contains structures by comparing the structure’s value with each other as seen in the screenshot.


The structures are changed like this (should not be doing that):
image
The 0-value contains an intact structure, and the 1-value has been destroyed… There’s something that’s wrong with my bubble sort

The whole array contains structs like index 0, but this image has been “sorted” so it has the broken structs too (like index 1).

EDIT: Apparently there’s some obvious mistakes in my code. I’ll fix them as soon as possible before returning to this thread!

Appreciating any help!
Thanks in advance.

The setting and the incrementing of the variable card_loop are in the wrong place. As it stands, the inner repeat will iterate 11 times over card_loop and card_loop + 1, without increasing card_loop (so repeat over the same 2 cards 11 times).

You’ll need to set card_loop to 0 at the first repeat, and increment it as a final unconditional event of the second repeat. You may also need to move the current condition and swap actions to a separate event.

Also, I’d recommend disabling the bubble sort, and checking that the player’s hand has all the cards that you expect in it via the debugger. If that checks out, then turn the bubble sort back on.

1 Like

This code works for sorting a normal array, containing numbers…
But I can’t seem to get it to work with arrays containing structures.
I’ve got a more primitive solution though, so if this isn’t possible, the world won’t go under :slight_smile: .