Somebody can teach me How to save a game?

I mean. I’m new to Gdevelop and until now, I don’t understand how the save works.
Can anyone teach me or show how its works?
All the examples taht I got , don’t explain nothing.
I don’t even know how to save in Xml or Json.
Can anyone show to me how this works?

I don’t know how to save the position of player in string, nor how strings work.

Assuming you are using GDevelop 5, If all you want is to save the state of the game, you don’t need to use XML and JSON, you can simply use the Storage events to read and write data in the web storage.
I did explain the storage events here in more detail:
wiki.compilgames.net/doku.php/gd … -explained

Hope it helps with the save-load example bundled with GDevelop.

In case you are using GDevelop 4 and native platform, it is basically the same, except GDevelop going to create and use a text file on native platform, but from your point of view there is no different regarding how to use the storage events and an example is also bundled there called basic level editor I believe.

Im using Gdevelop4 and I want to know how to save positions and variables

I Mean, save the player status , save the player number items , save the player position and Load it.
if I got this, my game gonna be so complete.
thanks for all the help

I’m afraid I can’t do any better than explaining each option and give you an example :cry:
Hope someone else got the time to explain in more detail :slight_smile:

Have a look my GD5 example online:
editor.gdevelop-app.com/?projec … /save-load

Good luck.

Thanks mate. With the examples, I can now figure out how its done.
Cheers.

Unfortunately I cant do anythiung. the strings don’t work, the saves don’t work. Nothing work.

I can’t even learn. thank for the help U guy over my post, but I gave up.

Which part of the example or explanation is that you don’t understand? Or how much do you understand from it?
Maybe you should try simple things first.

I would recommend to try the following in order:

1. Write a number in to a text file. If you succeed, that means at least you know how to set this up to write a value
2. Try to read the number from the text file that you have just saved. If you succeed that means you know how to set this up to read the value you just saved
3. try the 1. step and write multiple number in to file, each value in to it own group.
4. try the 2. step and read a selected number from the file using the name of group, if you succeed that means you understand the purpose of groups.
5. try step 3. and 4. with mixed value types, read and write text and numbers if you succeed that means you know how to save and load values using storage events

Only if you have successfully done the above and you managed to read and write pure text and numbers.
1. try to write values of scene and global variables in to file, you are going to need to use expressions
2. try to write values of object variables in to the file, you are going to need expressions
The expressions to use is listed on the page I linked where I explain the options.
3. try to write properties of objects in to the file such as scale, position, animation, again you are gong to need expressions you can find the expression with the expression editor, normally it takes the form objectname.PositionX() for example. You can find all this in the expression editor if you click the expression icon next to the field.

It’s easy to give up, maybe you can share an events screenshot to check it out?. Because many things can fail, and you need only one thing wrong to break it, for example write/read numbers with the action/condition to write/read strings and vice-versa, don’t use quotes in the groups or file names, read a number and save it in a variable and then read the variable as string or vice-versa, a logic problem itself (bad event setup).

ddabrahim, I tried with a simple value in string and everything worked well. thanks. I was almost giving up. but , can u show or do me a example how do you save the positions?
if u can’t , don’t worry. I’m grateful for the help.

This is what I do in the GD5 example I linked:
save-position.PNG

I would recommend to have only a single instance of the object in your scene and ignore the

  • ToString(character.Variable(ID)) part for now, don’t use it.

character.X() and character.Y() is the expression to get the current X and Y position of an object. Replace character with the name of your object.
If you manage the save the position of a single instance, then you can try to save the position of multiple instances.

In my example I use an object variable called ID with an unique value to identify each instances of an object and I use this variable in the group name so I know which group holds the position of which instance. characterX1 is going to hold the value of instance with ID = 1, characterX2 is going to be the position of character with ID = 2 and so on. It might be too confusing now, give it a try and save and load the position of a single instance only.

You can also try my example, and play around with it online in the online editor of GDevelop 5 I linked. The event is basically the same as GD4 so I would recommend to try my GD5 example but as I mentioned GD4 also has an example included, called basic level editor I believe.

Everything is working fine. just some ajusts on some variables, and I will finish the game soon.
Just need to finish the songs and sprites. Thanks for all the help.
Do you have any alias? I want to put in the special thanks credit thing.

It is really not necessary but in case you did find my help on the forum or my examples on itch.io useful, I would appreciate to see my itch.io page credited.
gametemplates.itch.io/

Thanks.

Hi, ddabrahim :slight_smile: Can you help me with saving and loading Duplicated Instances? I’ve tried tinkering with your save and load example but still didn’t get what I want.
I wanted to make a design game (think dress up game) that player can put any item they want into the scene. It could be 80 copies of the same items or different items.
I tried your example but i couldn’t save duplicated instances that was created using events, even after i made events that modify the newly created instance’s ID variable. It only saves the duplicates that I’ve already put on the scene (and not created using events).
I saw that the game gets heavier with duplicated objects on the scene so I wanted to have the duplicates created using events to decrease the size of the game.
Do you have an idea?

I’m not sure what the problem is.

In case they are instances of the same object, only the animation is different to display a different sort of dress,
The logic should be very similar to my save-load example. Add an ID variable to each instance and then using the ID save the info you want individually for each instance using a foreach event. Then when you load the scene, you can use a while loop to create objects while an entry with certain ID value does exist. Now the problem may be that in case you delete an instance with ID 5 and then create an other one with ID 6, there will be a gap between ID 4 and 6 and the while loop say oh it done, there is no ID 5 and break the loop and the instances with ID 6 and greater never be saved and created on load. So you want to make sure there is no gap. What I would do in this case, instead of generating an ID value when creating an instance, I would go trough each instances and generate their ID value just before saving to make sure there is no gap and then save.

In case they are instances of different objects like you have an object for shoes, and other for gloves, and other for hats then your need to go through the instances of each object type. Basically the same as above except you need to repeat the load and save logic for each individual object. Foreach shoes, foreach hats…etc So you probably want to create an external event for save and load that you can call.

I’m not very good at explaining things, I hope the above blabla helps somewhat.
I’m going to create an example for this later…

Also, I don’t follow this forum very often now, the only reason I opened this topic because you mentioned my name so you may want to consider to use the forum on my itch.io page in case you want to ask for my help with examples I made:
gametemplates.itch.io/forum

Please note, I don’t really want how to do this and how to do that questions in general on my forum, but requests for templates and examples or questions about templates and examples I made like this one.

For general questions and answers, always best to come here and ask any question you have to the GD community because there are more people here and more likely able to help you!

Made a basic level editor and added the option to save/load instances created on the fly.
You can download it from here, it is on the bottom of the list:
gametemplates.itch.io/gdevelop-examples

Still not entirely certain what was the problem on your side, it is basically the same thing, but works.
If you still have any problems, make a screenshot of your events and upload it to the forum and someone may be able to help.

ddabrahim You’ve explained so much. I just need to try and adjust it to my needs. Thank you so much! :slight_smile: