How to get my Instances saved on my Checkpoint?

Hey guys, how’s everyone doing?
It’s nice to see the community growing every day.
This is my first post, I hope you can help me.
Thanks in advance.

As you can see in the image, it’s a very simple system: When the player takes the Coin object, a point is gained in the scene score and the coin is deleted. This point is saved even if I leave the game and come back, thanks to the checkpoint and the save option (write).

So, I created the following: Unique coins through instances, this way the player can’t get the same coin twice in a row.

The problem is that the game records these coin instances without the player touching the checkpoint. I’d like to record the coins instances I’ve picked up ONLY when I touch the checkpoint, not just when I leave the scene. Just like happens with the coin score.

Any ideas? Thanks in advance.

Then you’ll need to change this - save first, then delete. It’s a guess to shat data gets saved:


Put the following event in a Beginning of scene event.

Also, you are assuming GDevelop iterates through the coin objects in the same order every time. It’s not something I’d rely on. You should either assign the coin id in the editor by hand, or store it’s centre co-ordinates instead of an ID. If you store it’s centre co-ordinates, then you can use the condition to check if the point is in coin object, and delete it if it is.

Hello MrMen!
Thanks for the answer, I understand everything you said, but I think I wasn’t very clear in my question:
The code I showed is working the way I need it to, it’s saving the score as well as saving the exact order of the coins.

My problem is here:

Write 1 in Coin.VariableString(Coin_Instance_Number) of storage “Gamedata”

then:

Coin.VariableString(Coin_Instance_Number) exists in storage “Gamedata”

I want to record the coin instances ONLY at the checkpoint, just as I can record the points, so the player does not get the same coin twice.
But, currently, these lines write instances ONLY when i leave the scene.

EDIT.: I want to create a system just like mario or sonic, you know? Take the coins, and save them at the checkpoint. I think i’ts the more simple a can get.

Ok, but currently you save it as soon as it’s collected.

So you’ll need a system that identifies the coin id as collected and saves it at the checkpoint.

2 ways come to mind:

  1. store the collected coin id in an array when the coin is collected, and save those array values when the checkpoint is reached.
  2. hide the coin when collected and add a boolean variable (set tot true) to it to indicate it’s collected. Then make 2 alterations - only collect a coin if the boolean variable is false, and another in the checkpoint collision to iterate over all the coins with the boolen variable set to true, and write their ids before deleting them.

Thank you so much, MrMen. :grinning: It’s working and the code sounds much more simple:

BUT THIS:

I’m sorry, i got no idea how to do this. Do you mean those “read and write storages” options in the engine? I’m new on those. I still studying. :thinking:
Do you mind give me the “north”? I really appreciate. :blush:

Well, I’m still studying, and for now I managed to do that, I changed the logic a little and changed the boolean for numerals. I think it’s more practical:

I feel like I’m almost there: Now I can record the coins at the checkpoint, but when I go back to the scene, they all disappear xD
I need to know how to register these coins individually at the checkpoint. I’m still studying save/load, but the expression process is a bit complicated (JSON, VarToThis, VarToThat, PARSE) for non-programmers like me.

What you’re doing is saving scene variable, “Collected”, to storage. But you’re never setting it anywhere. It’s not referencing the coin object Collected variable either. Since you’re using a variable on the coin object to determine whether it’s been collected, here’s one way to save and load that information. It’s a little longer and involved than I’d like, but it should work:

Start the scene with this:

And add this to the checkpoint actions:

Thank you for the help. I will work on this.