Good way to sort cards based on value?

I’m trying to convert a card game from Flash (AS2) to GDevelop. At some point, I need to be able to sort between 2 and 5 playing cards in order based on their value, for example:

9d c3 h11 (9 of diamonds, 3 of clubs and jack of hearts) would get sorted to:

c3 9d h11 (I need to designate the suits for the game, but they’re not important for sorting purposes.)

I’ve tried a few things without the best of luck, this was easy enough using arrays and sorting them, but since that’s not an option for now in Gdevelop I was wondering if I might be missing a practical way to do this? Would Javascript be the better option or is there any native actions that’d help?

Any suggestions much appreciated.

Thanks!

so you only sort max 5 cards?
with only 5 cards to sort through you can use bubble sort.
But i cannot say that thats a good way, but an easy one.

One way of achieving this :

  • Consider creating an object (say a sprite called CardsInHand) with 5 object variables (call them Card1 … Card5, or have a structure Cards with children 0,1,2,3,4 - it doesn’t really matter too much, except that it’s whatever you’re comfortable with)

  • Place the object to screen, and hide it.

  • Assign the cards to the object variables.

  • Sort the object variables, by shifting their values between them, into the order you like.

The advantage of this is that it becomes scalable if you were to add a player id, meaning you can have an arbitrary number of this object on the scene. And all you need to do it instantiate/create the object.

An alternative is to have a Global or Scene variable and doing the same.

Thanks for the replies, I tried the bubble sort (which I’m sure would have worked but I just have had some timing issues with things getting called simultaneously, and trying to stop it seemed to require a lot of workaround so I gave up.)

Ended up going with javascript (easy to make and sort arrays there) and passing back the sorted array to new object variables. Basically passed each card variable in so it was accessible, added each into an array, used a sort function (that ignored anything but numbers) then passed them back out into variables based on that sort.

Still a bit of a workaround but seemed to work. Thanks again.