Is adding localStorage objects possible?

What Wick Editor Version are you using?
1.19.3

Describe the Problem
Is it possible to add localStorage objects? I’m in the concept phase of an idle/incremental game and I just wanted to know if it would be possible to use wick’s scripting engine to save game data.

What have you tried so far?
I know with HTML you can use web storage objects like so:
// Store data
localStorage.setItem("gameLevel", "4");
// Retrieve data
document.getElementById("result").innerHTML = localStorage.getItem("gameLevel");

yes, with javascript not html

1 Like

yes you can save your game progress in cookies, local storage or indexedDb. All methods save on client side.
here you can find a post on saving preferences on cookies and/or localStorage:

1 Like

How can i mod this to be a game save or to save what frame was last played when a load save button is clicked
Game File: squareadventures3-4-2021_13-53-23.wick (803.0 KB)

// Store
localStorage.setItem("lastFrame", currentFrameNumber);

// Retrieve
savedFrameNumber = localStorage.getItem("lastFrame");
1 Like

how do i go to that point or use this with cookies?

Initially, when you retrieve, there will be nothing… you may check if is null. Then if is null, your “Continue from previous play” button should be hidden… Then, when you do save / or autosave (this could be done in every gameover), then local storage will be created using the localStorage.setItem.

The next time that you open the game and you retrieve using localStorage.getItem will be not empty, it will have the stored frame.

Is there a way to do this with cookies?

See 5 posts above this one, @blurredPixels posted it, but I have never done that with wick, so I can’t give you support on that one.

no we dont want to use cookies
cookies are mainly server side and localstorage is client side
so we want to use localstorage

Here’s an example of saving variables using your file:
squareadventures3-5-2021_10-49-13.wick (803.2 KB)

Try to play a level, then pause the project and play it from the main screen. It should take you back to the level you were one last when you click “play.”

Saved variables are easy to access when working with local storage, you just need to give every saved variable a name, and a value

window.localStorage.setItem("name", "value");

Then refer to them using the name to get the value you saved

window.localStorage.getItem("name");

I don’t think so, however cookies are intended to used with servers, which is why cookies are sent to the server everytime you make a request. I would recommend using local storage.

2 Likes