So I’ve been working on a very large game for a while now and have been hoping to put out a demo, but have encountered quite a few problems when it comes to getting the game to save and load content or export into a workable state.
I’ve included images of the save a load mechanics. The first image shows all the global variables being written once you click the proper button. The second image is on the same Event page and simply shows how the data is read once another button is clicked. The final image shows one of my other Event pages and how it should be reading the necessary data. The scene variable I’ve tied all this to is called “SAVEDEMO” and I have added it to every level in the same manner as you see in image #3.
Despite this, the game refuses to save global variables when I entirely close the game, reopen it, and then press load. I suspected that using the ‘Local Folder’ export method would make this tactic more viable, but the game is too large to be played via browser window and in rare cases where I have gotten it to play on browser windows, the game is extremely laggy and prone to freezing, especially when I attempt saving or loading. So my only other option appears to be turning the game into a downloadable app as mentioned before, though nothing I’ve found online has confirmed if saving or loading in the app version is even something that’s possible.
So my questions are specifically as follows:
Is my programming of the save and load features correct or is something off?
Can downloaded Windows apps save and load material at all or does it have to be a local file?
If it does have to be a local file, is there any safe way to reduce the number of files so the game isn’t a laggy/crashing mess?
Failing all that, is there some other export setting that I haven’t tried?
I’d immensely appreciate any help or advice on this matter. I am still relatively new with GDevelop, so the clearer/more detailed the response, the better.
I think I understand the purpose from reading that, but as far as actually creating child variables and incorporating them into this save and load process, I’m don’t think I see anything definitive.
I discovered you can create child variables beneath the scene variable, as included in the image below, though does this mean I would have to enter the name of every global variable here with the same numerical value of 0? And how would that look when placed on the condition/action bars?
Sorry for the confusion, this is just a side of GDevelop I’ve not at all worked with.
Here you are basically writing all values in the same variables, so only the last write will work. Either use another name for each variable and load all values individually or store every variable in a child of a structure, and save that structure, in that case the load is unchanged.
if you read the wiki page attentively it says local storage works only with scene variables. but of course you can write any kind of variable to it, but when you load them back they will be loaded as scene variables. you should write them in their place with hand. for example:
technically no, you can save any kind of variable directly, just the loading part needs this buffer scene variable. but after you do the global variables value to the loaded values, the buffer scene variables no longer needed in that session.
[Ctrl] + [C] => [Ctrl] + [V]. you only have to do it once, put all of the related events in an event group, and you can copy-paste the whole group at the same time. or you can use a variable structure as arthuro555 suggested.
yes. the “group” represent your variable in the local storage. so as you use different name to your variables in the code, you should use different neme to your groups in the local storage. you can organize your local storage with the storage name. like a folder structure in your hard drive.
Here’s what I have. Top image shows how I laid out my scene variables. They only look like this on one level though. I didn’t want to add them to other levels until I knew for sure that they were set up properly. That’s assuming scene variables even need to be on the other levels at all.
Second image is how the various data is saved. Once again, this is only present on this level right now until I’m told otherwise.
Third image is how the content is loaded. Again, it’s only applied to this level.
Fourth image is the loaded progression being applied. I wasn’t sure if all of these actions could be dropped onto the same action bar as the loaded content in the third image, so I put them in a separate action bar. Once all the actions in the third image have completed, I just altered a random object variable that triggers the content you see here in the fourth image. Not sure if that’s a good approach or not.
As it stands, in the preview window, clicking load doesn’t seem to change anything after I’ve closed the game and reopened it, but I’m not sure if that’s simply because all the content from these four images is only applied to one level instead of all of them, or if that’s because my coding is wrong or preview windows don’t actually have the capability to save and load content whatsoever.
Any further insights into cleaning this up would be much appreciated.
the preview use the local storage perfectly. if you have issues, you should use the debugger function to check the variables, and/or the developer tools to check the local storage.
your actions looks OK, but I’m not sure about the conditions. you should know what are you want to do.
just a comment: the events wich I posted earlier are part of my “at the beginning of the scene” group, so I didn’t use any condition to load and apply the values. it’s ok if you use conditions to load, but may be better practice apply the values instantly after load, without any condition because they actually belong together.
when you are done and everything works fine, you can create an external event from the loading events, and you can use that in the other scenes (if the used variables are the same).
Thanks! Is it alright for those scene variables in the top image to have no numbers attached to the right of their rows? Or will leaving them blank cause issues down the line if global variables change?
arthuro555 was also mentioning that my scene variables should include “structures”, which they don’t have here. Is that problematic at all?
I’m getting closer. Next problem I’m running into is setting up the external event properly. When I make a new external event, it asks me to choose an associated scene (seen in the bottom image). I can only select one, even though I’d prefer the event to apply to every level.
Just to test things out, I selected the first level ‘Alpha1’ and added the code you see in the top image. This includes the ‘read’ information and the load applications, both in the same actions column since you said that would be a good idea (I just cut off the bottom so it doesn’t look outrageously long). I also successfully added the external event link to all the necessary scenes.
Upon pressing play, some of the games global variables seem to no longer exist or operate properly, whilst others seem fine. Pressing save or load on the necessary page doesn’t seem to have any effect either. I’ve checked the code several times and don’t spot anything off. I’m hoping it’s not an issue that requires I enter the debugger mode, since that’s another facet of GDevelop I know very little of.
One External event sheet with all Globals and LocalStorage i call this MainGlobals
A GameScene to rule all levels, hud, and other external layouts, and in this GameScene a link of MainGlobals, later in my levels i just add a link to the GameScene and it’s own logic.
don’t worry about it. when you add the link in other scene, this window will pop-up again.
I’m afraid this is it. if you are serious, you have to learn sooner or later. it’s very helpful, and easy to understand in GDevelop. and only you can check runtime, when the value of a variable changes. I can’t see from here what happens and why.