Storage Help?

This is probably easy, but from some reason I just don’t understand :frowning:
Anyways how can I go about making my game save?
It’s kinda simple. I just want it so that whenever you finish a level go back to the select screen and unlock the next level. I was going to have a variable counting up, but I couldn’t get it to save… or work whatsoever… Anyways I just want it to remember how many levels are complete. Any ideas or concepts that can make that work? There’s only seven levels total. So hopefully it won’t be too hard. Very sorry if this has already been asked hundreds of times. I did search around and didn’t see anything helpful.

To write a value in to a file is easy. Just use the storage action to write value in to file.
For file name you can enter anything but make sure the file name is between “” so “file name”.
Group can be anything again, groups gives you the possiblity to store multiple values in the same file and be able to read any of them later. Finally, just enter the value you want to write in to the file.

You can read a value from a file the same way using the read value storage action, but to read the value you also need to use a variable that is going to store the value in your game.

In your game I would simply write 2 in to the file when level 2 unlocked, 3 if level 3 unlocked, 4 if level 4 and so on and simply when the player goes to the select screen, read the value from the file in to a variable and check the variable. If it >=2 then level 2 unlocked if it >=3 then level 3 unlocked and so on.

When a level complete, make sure you write the value in to the file, before you go back to the select screen and make sure you read and write value only once at the time using the Trigger Once condition.

Thank you very much! It’s quite clear now. :smiley:
I didn’t realize I had to kinda turn the expression into a variable, and I think that’s what I missed.
I got it working now though so thank you :slight_smile:

Okay now it’s not working… Well it is but not quite.
Okay so after I beat the first level it goes back to the menu and level two is unlocked. So I know it’s reading and writing.
What I don’t understand is after I close the app. Whenever I open it again I’m back on level one? What did I do wrong? What didn’t I do right? :frowning: Do I need to use a special plugin in intel xdk or something? (It’s also no longer working in chrome) Only way it works is if I compile it to native. It works just fine that way :neutral_face:

I do experience the same :confused:
Also, the game is running in preview but when I export I get this error message in IE11 while hangs on the loading screen at 50%:

storagetools.js var rawStr = localStorage.getItem("GDJS_"+filename); Unable to get property 'getItem' of undefined or null reference

You might say, hey it IE…but it works in preview and doesn’t works in exported game it hangs at the loading screen. It seems to me the browser is unable to get the localStorage so in other browsers it might just go ahead and create the storage with the value 0 (so we are loosing all the progress made before) while in IE it hangs up with this error. So it could be a bug in GD.

Anyway, here is the project in case somebody would like to take a look and see if we are doing anything wrong or it a bug: (15.9 KB)

A search on the Internet shows that the local storage feature is broken on some versions of IE11 (especially the version not updated from Windows 7 SP1).

I get the error message only in IE but still, it doesn’t seems to work nor in Firefox or Chrome :confused:
Also as I have mentioned the game launches in preview in IE11, I get the error message in the exported game.

I managed to fix it temporarily by loading the file at the start of the scene with the “Load a structured file into memory” action. Weird fix but it worked for me. Maybe it’ll fix the example too if your still having troubles?

Nope, it didn’t solved the problem in my project but I was able to solve the problem using JavaScript.
I decided to use JS to read and write local storage and it works in all browsers including IE11.
Definitely there is a problem with the way GD read and write local storage since my JS code works but GD’S storage actions doesn’t.

In case, you going to experience further problems using the storage actions, here is the project with JS: (17.5 KB)
Note that, JavaScript works only in HTML5.

An interesting thing, if I was loading a level first, complete it and then go to start screen, it solved problem but if I was loading the start screen first I just couldn’t get it to work using storage action whatever I was trying to do :confused:

In case if 4ian or Victor would take a look what could be the problem using storage actions, it here:

Using the “Load file” and “Close file” actions, it will work.

There was indeed a problem, it’s fixed! :slight_smile:

To fix it for your games without waiting the next version, go to /JsPlatform/Runtime/ then replace storagetools.js by this one: … getools.js

(The change are really simple, actually: … 7f9b5afc60)

Yay thank you so much! I can’t wait to try this out ^-^