How to take a random object from a group and then put it into some sort of variable?

I’m making a card game so I need to select 2 random cards, one for each player, from a group of objects, or the deck, and then compare each player’s drawn card to see who wins. But I don’t know how to take the randomly selected card (I used random) and put it into a variable which then I can compare. I might be taking the wrong approach though.

And help is very much appreciated, thank you!

I’d look at storing all the cards in an array (scene or global variable), and select 2 random cards from that, and then working out what to display.

1 Like

Thanks, will look into that. After randomly selecting from the array though, is there a way to store it, and then compare them? Because aren’t I just doing the same thing but with an array?

Either put the results into other variables, and compare those two variables,

Or store the two random numbers for the position in the array, and use them to reference the values in the array.

That’s the problem though. How do I go about this? Tried doing this in the action but I can only add, subtract, etc.

You can also use “set to”. Here’s a snip of a way of doing it:

Thanks, a bit confusing, but could help. Is there a tutorial on creating arrays in gdevelop?

edit: Are there any placeholder tutorials at all? Because now I need a way to display each player’s drawn card that was randomly selected and was put into a variable (or at least I think it was) in a specific spot.

Did you look at the Pairs example? It uses placeholders.

Thanks, I’ve seen that though and it doesn’t quite make sense. It’s not quite what I need and doesn’t easily show how it works as I’ve looked at it for another problem I had.