Unlock levels by global variables

Get help using Construct 2

Post » Wed Jan 23, 2013 10:39 pm

Hi, I want to unlock the levels of my game by the global variables and save this by webstorage. But the webstorage can't work. How can I do this??

I tried this:

(except level 1, the other levels have a global variable: level2, level3... whit initial value 0)

On end of layout(level 1) --> set level2 to 1
                             set local key "lev2save" to "level2"


And in the event sheet of levels:

if level2 is=1
on touch object     --->go to level 2
On start of layout ---> Set level2 to Webstorage.localvalue("lev2save")

Now, if i deactive this (On start of layout ---> Set level2 to Webstorage.localvalue("lev2save")) level unlock work, if this is active the level remains locked (or unclickable), so I think I'm wrong on the condition for save the level unlocked, right? Maybe I need another condition to save the variable??

Please help!

gamegamegame2013-04-02 23:32:18
B
17
S
5
G
3
Posts: 76
Reputation: 2,948

Post » Wed Jan 23, 2013 11:29 pm

@gamegamegame cesisco made a nice example .capx on how do this maybe it will help:

Webstorage multilevel savingWink2013-01-23 23:30:21
B
50
S
11
G
8
Posts: 479
Reputation: 9,911

Post » Wed Jan 23, 2013 11:38 pm

Ok thank, I try this.
B
17
S
5
G
3
Posts: 76
Reputation: 2,948

Post » Thu Jan 24, 2013 12:15 am

seems that work. But if it run on a mobile device, maybe by appmobi, how the game save? I know that webstorage use cookies of browser, so in a "native" app for mobile, it use the mobile browser or? can someone explain?
B
17
S
5
G
3
Posts: 76
Reputation: 2,948

Post » Thu Jan 24, 2013 12:32 am

I haven't tried appMobi in a while I'm still waiting for them to get direct canvas working with Android but this method should work with appMobi. I have used it with CocoonJS, and it works good.

WebStorage will save whatever you tell it to inside of the mobile devises default browser. I usually, add a reset game option someplace in my game so people can erase all the webstorage data, and start over fresh if they want to.

You can do this by creating a image button representing a restart symbol. then give it a on touched object event, and then a clear local storage action.Wink2013-01-24 02:08:49
B
50
S
11
G
8
Posts: 479
Reputation: 9,911


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests