[SOLVED] LocalStorage 'set item' not saving..

Get help using Construct 2

Post » Sat Sep 12, 2015 5:33 pm

I have this currently in-game: on death -> Localstorage set item "savedCoins" to invCoins (global variable that adds coins when picked up).
And that part is working, when I'm going back to the menu, it still shows the amount. But when I refresh the page, it resets to 0. Why is that? Pictures of the events are below:
Image
This is the part actually saving it.

Image
This is the part setting the saved integer to my global variable.

Why won't it save when I refresh the page? Does this not work on preview in browser, for some reason?
Last edited by condolent on Sat Sep 12, 2015 5:45 pm, edited 1 time in total.
Website Twitter Indie Developer
B
20
S
6
G
4
Posts: 206
Reputation: 2,954

Post » Sat Sep 12, 2015 5:45 pm

Solved, wasn't actually GETTING the key on the second image, I was checking what to do after I got it without even getting it. (stupid)
Solution:
Image

Thread can be locked!
Website Twitter Indie Developer
B
20
S
6
G
4
Posts: 206
Reputation: 2,954

Post » Sat Sep 12, 2015 5:48 pm

In order to load it you need to do all three steps shown in here: https://www.scirra.com/tutorials/1461/h ... age-plugin

On event > Check item exists
On item exists > Get
On get > set
B
17
S
7
Posts: 280
Reputation: 2,522

Post » Sun Jan 03, 2016 11:24 pm

RayKi wrote:In order to load it you need to do all three steps shown in here: https://www.scirra.com/tutorials/1461/h ... age-plugin

On event > Check item exists
On item exists > Get
On get > set


Justr trying to get the hang of localstorage, seems the "get" step is no longer necessary?

Note #2: Thanks to an user comment. It isn't necessary to call 'Get Item' on 'Check if item exists'. So you can use 'LocalStorage.ItemValue' directly in the 'Check if item exists' event.


So we can just On event > Check item exists > On item exists > set
B
41
S
12
G
14
Posts: 1,122
Reputation: 11,282


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests