Transfer progress from one scene to another

Hi guys how are you? I have to ask you for advice…
I’m developing a survival video game in which once all the enemies in the game have been killed, the scene is changed and a new room with other enemies is recreated.
there are different types of weapons that the player can collect and use to defend themselves and I would like the accumulated ammunition and game progress to be transferred from room to room.
I’m currently using scene variables but I think I need to change everything to global variables unless there are other ways to not change all my variables.

I attach a screen example of variables present for a single weapon, the same is present for 20 other weapons

Holding the information in global variables is the best practice.

However, this means refactoring a lot of scene variables into globals. Which will be a bit of a pain, especially if you miss changing any variables.

So an alternative is to JSONify all the variables you want to take across scenes, store the JSON string(s) in a globals, and then unJSONify(?!) them in the next scene. And the more variables that are already in a structure, the easier is is to do this.

An alternative to this: Are you storing the current scene variables at all? You may want to consider using local storage if you want the player to be able to continue from where they last finished. Then you don’t need to mess around with globals, instead loading the values at the start of the scene and saving them at the end.

1 Like

Mr. men thanks for your intervention, forgive me, I’m not very familiar with json files… I tried adding one of the many variables and it seems to work.
How can I add multiple variables in a single file?

can someone help me? how can I store all the above variables in one json file?

Put a dot in them all. Like caricatore.pistola, caricatore.revolver, caricatore.mitra etc. It makes caricatore the variable and the guns are all children. Or at least it used to, it might be different if you’re doing the thing where you have to prewrite all variables. No clue. Also it makes them easier to read, I must say. Then save caricatore.

Edit you might want to search and replace to add the dot.

1 Like

What @Lucky-j suggested is the path I’d take too. You’ll be best to declare the structure in the scene variables first, and then run a search and replace on each event sheet.

To save you just need to JSONify the structure (so only caricatore), as it’s children will be automatically included.

1 Like

I’ve tried to change maunally 2 variables (caricatorepistola and caricatorerevolver) and apply the structure variable caricatore. and pistola - revolver as children, it seems to work. But I have to rewrite all the variable in the game, so I wanted to know if there’s a way to rewite all the variables with the same name all in once. I also tried to apply the JSON strings but it works only on 1 variable (caricatorepistola) and I don’t know why.

There is. But save a copy of your game.json before you start.

  • Rename the structure to something like tempPlaceholder, and save the game. This is so it doesn’t get renamed in the step below and possibly corrupt the game file.
  • Once done, open the game.json in a text editor and replace all occurrences of caricatore with caricatore. (so with a dot at the end)
  • Save, and reopen the file in GDevelop. Rename the structure variable tempPlaceholder back to caricatore
1 Like

ok I opened the json in a text file and modified it by inserting the dot to the variables that interest me and everything seems to work.
just one last question…
in addition to the weapon magazine variables, should I transfer other saves of other variables (life, stamina, weapon held by the player, etc…) for this reason do I have to create another json file?

Ideally you would set up your variables at the start of the game development so that all those that need to be stored/saved are under one parent variable.

But, given that you’re already a good way into your project, you could use this alternate method. Create a structure variable as the “umbrella” to hold all the other variables you want to save. Add all the variables you want to save as children of the umbrella variable. Once done, jsonify and write that one umbrella variable.

1 Like

ok now everything is clear thank you very much