How do I use webstorage on level select

Get help using Construct 2

Post » Tue Dec 02, 2014 2:20 pm

Hi how do i use webstorage to keep the levels unlocked once they have been passed. I used a simple level select tutorial i found where each level has its own global number ie level1,level2,level3 ect. they all = 0 till you pass the level and it will add 1 to unlock the next level. I have only ever used webstorage for highscores and can't work out how to adapt it for what i need it for.

any help would be great and thanks in advance
B
10
S
2
Posts: 7
Reputation: 705

Post » Tue Dec 02, 2014 8:09 pm

if your levels are linear, you can just add a var 'level' starting at 1 and add 1 to it when you finish a level.
then save it to webstorage - add key="level" value=level.

if not i recommend you add a dictionary instead of pre-adding all the levels as vars (may be a lot of them) and push a key to it every time you finish a level - add key="level"&level (value doesn't matter, if you want to keep an extra state of the level you can write it in the value, i usually write down another json in the value with all my data).
then save this dictionary to json to webstorage.
Image
B
78
S
29
G
12
Posts: 515
Reputation: 12,559

Post » Tue Dec 02, 2014 9:32 pm

thanks for the reply Lof

I did try to have one var like you said done it the same way just added 1 per win. The problem i had with that was you could just play the 1st level over and over to unlock all the other levels. but i think it might just be easier to do it that way and hope people don't work it out.

and il have to have a look into dictionary

Thanks again
B
10
S
2
Posts: 7
Reputation: 705

Post » Tue Dec 02, 2014 10:05 pm

so have two vars 'level' 'nextLevel', set level to the right level at the beginning of each level and then when you finish set 'nextLevel' to level+1

or to be exact set it to max(nextLevel,level+1), so if you'll reach level 10 and go back to play level 1 it won't return to 2.
Image
B
78
S
29
G
12
Posts: 515
Reputation: 12,559

Post » Sat Oct 24, 2015 8:19 am

@provokedninja did you figure it out? can someone post a capx? @lof
B
10
S
1
Posts: 93
Reputation: 722

Post » Sat Oct 24, 2015 8:47 am

garyrossiter wrote:@provokedninja did you figure it out? can someone post a capx? @lof


Webstorage is deprecated. You should really look at using Local Storage now.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
86
Posts: 5,416
Reputation: 59,518

Post » Sat Oct 24, 2015 11:07 am

zenox98 wrote: Webstorage is deprecated. You should really look at using Local Storage now.


how we can save arrays in local storage
Image
B
64
S
39
G
46
Posts: 656
Reputation: 32,728

Post » Sat Oct 24, 2015 12:23 pm

luckyrawatlucky wrote:
zenox98 wrote: Webstorage is deprecated. You should really look at using Local Storage now.


how we can save arrays in local storage


Wouldn't that be as easy as setting the item to Array.AsJson ?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Oct 26, 2015 6:49 am

Yup just save it to json then load it from json.
Image
B
78
S
29
G
12
Posts: 515
Reputation: 12,559

Post » Mon Oct 26, 2015 9:58 am

OK i can save by arryay.as.Json
but how to load it on startup
Image
B
64
S
39
G
46
Posts: 656
Reputation: 32,728

Next

Return to How do I....?

Who is online

Users browsing this forum: ultrafop and 37 guests