Save and load using storage system?

Im having problems Loading and Saving using the storage system.
Here is the Code:


Every time I quit the preview and start another one, the values don’t change.
I used the debugger to check variables but they don’t load and I’m not sure if they save either.
Any help would be appreciated greatly.

Do some checks, first check the variables you’re saving are the same type if they are number must be saved/loaded as numbers and if they are strings the same process.
The load storage added in your game that way is not correct because is calling Load storage “inventory” in memory every frame, try moving it to add a trigger once and every time you need to load the storage do it with Read instead.
Tip: What I do for save/load is to create a separated Events called Storage so then manage all related data.
Something like this


then in the GameScene events just add a link

When you need to modify some value in your gamescene logic do like

Other thing I notice is you read the data from a scene variable and pass to an object variable I don’t know way, there will be more than one instance of player?
If the answer is not, then way that conversion just use the scene variables to store the values.

Ty I will check. There is only one player with a object variable for each item i.e.
Wood
Stone
Carrots
Etc

And I want to save the amount currently in the Players inventory and Load it the next time I open the game

But way don’t you try the inventory built-in like in this example

Or just a simple one like in the official example
https://editor.gdevelop-app.com/?project=https://resources.gdevelop-app.com/examples/inventory-system/inventory-system.json
I’m telling this because if your game go bigger and need more items and weapons, armors storing all in object variables could it be a pain.

Using the inventory extension, I cannot load a certain amount, say 10 stone from a previous save into the inventory. I can only add one item at a time.

So my player had 6 stone from the previous save, but when I want to load that into the inventory it only asks for inventory name and Item name, and not the amount of that item.

So I guess that it wont work using the inventory extension

I found a way around this:

I read from storage “inventory” and store value in Stone.
Then I add a repeat and repeat it Variable(Stone) amount of times and inside of it I have “add “Stone” to inventory"items”"

So basically Im adding the amount of stone, 1 at a time, to the amount of stone that was saved.

Sorry if this is very confusing

Sure one at a time but in case you need more just do
Repeat x times and inside the repeat event
Add to inventory item “name”
Where x is the number of items you collect or buy

Look deeply the inventory system of the official example
So my player had 6 stone from the previous save, but when I want to load that into the inventory it only asks for inventory name and Item name, and not the amount of that item.

So I guess that it wont work using the inventory extension

Let me an hour and I’ll prepare a tutorial of this, using Object variables and Storage.

2 Likes

Ty,

I just added the amount of stone saved in the repeat therefore:
If I had six stone and I add them 1 by 1 to the times of stone ot would be 6x(+1).

This worked excellent, but I’ll take a look at your example. If it works better, I’ll use it but either way, thank you!

The video is coming anyway, is uploading right now.

Good :+1: (20 char 20 char)

Hi mate Do you sleep? LOL

Hahaha
Yeah. (20 char 20 char)

Here the project https://drive.google.com/file/d/158grx3xdRTdUBuZrPCi7VXW0hmkKbFYd/view?usp=sharing
Here the tutorial: GDevelop 5 Tutorial - How to use Storage for Wood and Stone - YouTube HD is processing now so wait a little bit.

Sorry in the tutorial i totally messed up with the names of the Storage and the keys to save, but later is fixed.

3 Likes

Ty, I will take a look at this.

1 Like