Create random objects in a select positions

New to Gdevelop and this forum- apologies if this isn’t how I’m supposed to ask questions or if this question has been answered before. I’m trying to make a game when the scene begins to randomly create 5 random cards next to each other in a sort of ‘hand’. I attempted to do so by creating a variable where it will choose a random id and then based on that id show a card, but the problems comes when I want to position the cards e.g. card 1 in hand etc. What I was doing was that I created a variable called ‘cardsinhand’ and added 1 to it after each time a random id is created. What I would like to do is when there are no cards in the had ie. variable ‘cardsinhand’ is equal to zero, create a card with a random idea so therefor a random card and put it at an x value for the ‘first position’ and then when another random id is generated to put that card in the ‘position 2’ spot. What I had done was add 1 to the ‘cardsinhand’ variable and then when another id is created because the ‘cardsinhand’ variable increased to 1 I would create the random card and set the x value of said card to a number I don’t know maybe ‘320’ + ‘cardsinhand’ x 22. The idea was that when the ‘cardsdinhand’ variable is 0 the x position of the random card would simply be 320 but as more cards are added into the hand, the x position would increase so the cards would move further along. Unfortunately, for some reason only the last card shows up in the last position and I’m unsure why. Sorry for the overdetailed explanation and again I am brand new to gdevelop and really don’t have any sort of programming experience so I’m sure I’m missing something. Thank you.

:wave: Hi and welcome here :slight_smile:
I think your cards are all stacked at the latest position. You can verify that in the debugger, checking the number of instances and their position.
Once a card has been dealt, toggle a variable, like handed = true.
And when you want to pop and position a card, check that handed = false.
It may or may not work, depending on how you built your game.

Thank you so much! I’ll try that and see if it works.

I checked the debugger and that seemed to be the issue. I tried what you said and it seems to be working so far. Thank you!

1 Like