How to save the game on PC and mobile

Hi,

I have been trying to find methods to store games on computers and mobile devices online as well as in AI chats, but the more I search, the more I become confused.

Could you provide me with a systematic approach for saving the game on both a computer and a mobile device?

thanks,

Have you checked out the two GDevelop tutorials?

Intermediate method tutorial

Advanced method tutorial

Thanks.
Is there any place where I can download this game?
Can you recommend a reliable text tutorial for this situation?

You set your stuff to variables for example global structure
Like you make structure called Save and add child to it make it number variable and call it PlayerHP
Now you call it by GlobalVariable(Save.PlayerHP)
But if you add another child lets say PlayerAmmo
You call it by GlobalVariable(Save.PlayerAmmo)

Now instead of saving both variables separately you do it only for structure variable which in this case is Save
So you go with

But I’ve come across some tutorials and code that recommend using JSON to save!"
In GDevelop, there are functions available to perform this task.

The ZeroX4 answer is very helpful.
But still, I will be happy if you tell me how to save the game as Jason file.
I am still searching and trying to find the answer!

regards,

IF your goal is to have some file you can give me for example send via email or on discord
And now i can load it and i now play on your save file

Then if i remember correctly on mobile it is restricted not by gdevelop but by android

As for exporting itself
IDK how that would work i would assume SOME way of uploading string of data would be possible somehow (idk how idk where so do not ask me how to do it) and then you could download it and save in some file

Imagine as if something is sent to your clipboard when you click some button
Or even here under your post you have icon of chain
image

If you click it then link to this post is copied to your clipboard automatically

But again do not ask me how to do it i have no idea
I just am aware in theory it should be possible one way or another

It sounds like this action is work:

But the problem is it needs all the structure childs. How can I add all children of structure?

You can see my game save global variable:

Do you have any idea about it?

You would go with just GameStats
BUT
I think you would need 2 things
Yet keep in mind i never did it and i do not know if it exist
I know how to save something to json and then load it into variable
Which is our most basic save/load system
IF you could save this GameStats structure to json then save it into text file
And then load that text file convert what was inside that text file back to json then you are home

Yet again i never done that idk how to do it where on top of that
I THINK that it would not work on android unless you have root access to your phone

So A LOT IF there
And i do not know answers you seek
You should 1st try to spit out whatever idk let’s say “blablabla” using action you found
If you somehow be able to export text file on android containing “blablabla” then you are already half way trough
Literally in String(text) field type “blablabla”

If you will be able then to save and find that file on your phone then i say rest is just matter of asking how to store json format inside text file

Based on your knowledge, can you show me a sample code so that I can save my file on a mobile phone and then load it?

Is it possible for you to see how I work in this game and then tell me your opinion about saving?

I can place the link here.

I already told you i never done it and idk if its possible yet i am aware technically it should be possible while it still does not mean it is

And based on my knowledge as i told you
As far as i remember you need root access to your phone to be able to export files from your game in gdevelop which is limitation of android and not gdevelop

Where also i never done and idk how to export anything online
However i do know you can export some string
At 33:29 you see how this guy is able to export something as string and export it just by clicking to clipboard
I would assume same exact thing would work on android

YET you are the one who need it so you should watch the video and try to pinpoint which event is responsible for that mechanism

And idk how long of a string clipboard can hold
That is why i said technically it should work
Yet i never tested it i never done it i have no practical knowledge over it so my knowledge is at exact same level as yours
I am not even 100% sure if you could export somehow json string into clipboard would it not lose its formatting after you paste it over somewhere else

So like i said it is a lot of IF’s

2 Likes

Hello, what are you trying to do? Do you want to save a score or how much gold the player has? Save a file that can be exported and shared with other players?

I need to save the score, level and golds on PC and mobile.

Oh ok, that’s pretty simple once you get used to it. You almost had it right in the image above. Except you need “Save a text” because “Save a text into a file” is only for those os listed.

You can not save a structure variable as a text unless you convert it into a string/text. This is why in the image you see ToJSON(GlobalGameState). GlobalGameState is a structured variable and I can not save it as a text unless I use the ToJSON thing.

When you load your saved GameState, it is now a text so you can not put it back into GlobalGameState, because that is a structure. Here I make use of a GlobalTempVar of the type Text to load my saved GameState. Then I convert the string that I just put into GlobalTempVar and store it into its correct structure variable GlobalGameState.

If you will like to see the small example work, the project file is at
https://drive.google.com/drive/folders/1jacqrLIIDD-WJNoQesFhjLW_gVyIJOSs?usp=sharing

Absolutely! In GDevelop, there are indeed functions and methods available that make use of JSON for saving data.

Thanks for your reply. It’s really helpful, but a question that comes to mind is: where is the save path? on desktop and mobile?

And in which condition should the file be written on the server and firebase?