How do I use the LocalStorage Plugin?

Get help using Construct 2

Post » Sun Aug 02, 2015 7:12 am

I just tried implementing localstorage into my game, and I found an issue that I would like to hear anyone's opinion on.

I am using an array to store which levels have been cleared, and which is still locked because the previous levels haven't been cleared. The problem I am having is that previously, I would load the array and set each button's animation frame to display the appropriate frame as a sub event to the on start of layout event. This ensured that everything was set up immediately at the start, and the player will not notice it.

But since LocalStorage can only be used as an event and not sub event, I placed the button animation frame loading events as a sub event for the On item get event, since I thought it made the most sense to put it there and have it load immediately once the value has been retrieved, and also to ensure it only loads once. But the problem is that loading the LocalStorage takes a small but noticeable amount of time. When loading the page, you will notice the button frames changing from default animation frame to the loaded one.

I was curious what others are doing to counter this loading time to ensure that it isn't noticeable for the player? Is the only option to use an earlier page to load all the values than when you go to the next page, do not reset all global variables but use the earlier loaded variables so you can add it as a sub event to the on start of layout event? Or is there another way to get it to load much faster?
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Mon Aug 03, 2015 7:06 am

firezombie444 wrote:I just got it to work right, i changed the key and variable names and then it worked. Thanks for the help!


Then an old LocalStorage key with the same name was in your cache of your browser. In this case just purge the cache & cookies in your browser.

Regards
Andreas
Image Image iTunes: Match3 | Google Play: Match3
B
106
S
39
G
31
Posts: 1,172
Reputation: 29,233

Post » Mon Aug 03, 2015 7:13 am

rekjl wrote:I just tried implementing localstorage into my game, and I found an issue that I would like to hear anyone's opinion on.

I am using an array to store which levels have been cleared, and which is still locked because the previous levels haven't been cleared. The problem I am having is that previously, I would load the array and set each button's animation frame to display the appropriate frame as a sub event to the on start of layout event. This ensured that everything was set up immediately at the start, and the player will not notice it.

But since LocalStorage can only be used as an event and not sub event, I placed the button animation frame loading events as a sub event for the On item get event, since I thought it made the most sense to put it there and have it load immediately once the value has been retrieved, and also to ensure it only loads once. But the problem is that loading the LocalStorage takes a small but noticeable amount of time. When loading the page, you will notice the button frames changing from default animation frame to the loaded one.

I was curious what others are doing to counter this loading time to ensure that it isn't noticeable for the player? Is the only option to use an earlier page to load all the values than when you go to the next page, do not reset all global variables but use the earlier loaded variables so you can add it as a sub event to the on start of layout event? Or is there another way to get it to load much faster?


Hello @rekjl

I'm facing the same problem. I excluded all my LocalStorage function in an extra event sheet called 'es_LocalStorage' and included the event sheet in all event sheets where I need the loading function. When my levelselection screen comes up the player first sees all levels as locked, then when the LocalStorage has been loaded from the LocalStorage the LevelsButton Animation changes to unlocked.
It's just a little time frame but it is noticable.

It helps if you use a menu and a levelselection as separate layouts. Then you can fetch the array at the menu, so the values are already available in the levelselection screen. Otherwise I have no idea at the moment to work around this issue.

Regards Andreas
Image Image iTunes: Match3 | Google Play: Match3
B
106
S
39
G
31
Posts: 1,172
Reputation: 29,233

Post » Mon Aug 03, 2015 7:34 am

@AndreasR. Yup I ended up doing that, had to do a few changes to my game but made sure everything loaded in the first layout, than manually reset all global variables one by one in the on start of layout event. My first page also displayed the percentage of levels completed, so to counter the time it takes to correctly display it, I added an animation of the numbers moving at random before showing the correct one after 1 second. Haha at least I think the player will not notice that it was there to cover up the slow loading.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Sat Sep 05, 2015 11:09 pm

My variable is NaN which I heard is "Not a Number" but I followed all the instructions:

Screenshot of the events:
prntscr (dot) (com) / 8d23zg

Screenshot of score:

prntscr (dot) (com) / 8d24lo

What is my problem?

Edit: So apparently I am not able to post links... So that's why the links look like that.
B
4
Posts: 2
Reputation: 204

Post » Sun Sep 06, 2015 7:26 am

bobofettbr wrote:My variable is NaN which I heard is "Not a Number" but I followed all the instructions:

Screenshot of the events:
prntscr (dot) (com) / 8d23zg

Screenshot of score:

prntscr (dot) (com) / 8d24lo

What is my problem?

Edit: So apparently I am not able to post links... So that's why the links look like that.


Hello,

can you provide a capx example or a screen shot of your code?

Regards
Andreas
Image Image iTunes: Match3 | Google Play: Match3
B
106
S
39
G
31
Posts: 1,172
Reputation: 29,233

Post » Mon Sep 07, 2015 2:53 am

Nevermind actually, I figured it out. :)
B
4
Posts: 2
Reputation: 204

Post » Mon Sep 07, 2015 5:27 am

On your second layer all you did was:

Set text to player coins, set player coins to player coins in local storage, and make a button.

You didn't fetch the value at all, and set it to the text... try that in start of layout...
B
7
S
2
Posts: 92
Reputation: 663

Post » Mon Sep 07, 2015 7:32 am

Message: FergusB is not yet permitted to post plain text URLS (300 rep required). 2 URLS removed. Why?
The plug-in is automatically included in the latest version. So, just download the latest stable version of C2, you have the plug-ins included.
Last edited by FergusB on Thu Sep 10, 2015 3:37 am, edited 1 time in total.
B
2
Posts: 1
Reputation: 152

Post » Wed Sep 09, 2015 10:03 pm

@AndreasR

can you help me out please!?

i was used to webstorage (wich was fine by mine opinion) and now its gone and im stuch with this LocalStorage that i just dont get... :(

I have numerical value stored under key "X"
and i want to compare it and see if that value is equal or under "9" and than ad zero infront of it so that value looks like "09"
Websorage had "compare key value" and that worked excellent for me... but no im stuck with this crapy LocalStorage and dont know how to proceed... :(

HELP!!!!
B
31
S
13
G
2
Posts: 750
Reputation: 5,535

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: irina and 5 guests