# How do I save the position of multiple draggable objects?

Hello!
I am very new to GDevelop, so excuse me for my lack of knowledge.
I have a card game where the cards can be dragged around by the user and I need a method to save the position of every ‘card’ (or object) in the game so they can open the app again later and keep playing.

I saw a similar request about saving draggable objects, but I could not make sense of it.

Thanks!

First assign 2 variables to the card call this PosX, PosY so when you create the card in game set PosX = card.X(), PosY = card.Y() then check
if card isdragged (invert) (this means is not been dragged)
Condition → card.X() not equal to card.Variable(PosX)
Condition → card.Y() not equal to card.Variable(PosY)
Action —> Set card position.X to card.Variable(PosX)
Action —> Set card position.Y to card.Variable(PosY)
If I have some time I will prepare some example for you.

1 Like

Do I have to manually go into every object and assign a variable? Because I have 2,500+ cards and that would be a pain to go through at this stage

Is this right?

I’m recording a tutorial for you is going to be live in minutes.

3 Likes

Here take the example its easy to understand, if not wait a few minutes for the tutorial.
Draggable Cards Example
Here

Sorry my microphone is broken and my voice is so far away.

3 Likes

Is it possible to assign an ID to each card? As mentioned before, it would be quite a process to give every card an ID

The same way you assign PosX or PosY you can add a counter and increment its value in the foreach at the begin of the scene

Logic is this
At the begin create a variable type number called CardsCounter = 0
In the events Foreach inside at the begin Assign Set Card.ID = CardsCounter and just below this set CardsCounter += 1

So every card is going to have an id.