Unlock Level 2 when Level 1 is completed

Discussion and feedback on Construct 2

Post » Sun Mar 13, 2016 10:56 am

How to unlock level 2 when level 1 is completed using LocalStorage?
B
10
S
1
Posts: 93
Reputation: 722

Post » Sun Mar 13, 2016 11:37 am

You should use variables to unlock different levels, and save-load that information using local storage at the beginning of your game.
B
137
S
33
G
17
Posts: 1,560
Reputation: 20,802

Post » Sun Mar 13, 2016 11:49 am

@glerikud Can you provide me a sample capx it would help alot
B
10
S
1
Posts: 93
Reputation: 722

Post » Sun Mar 13, 2016 12:15 pm

Sure, here you go:
https://dl.dropboxusercontent.com/u/166 ... ample.capx

Is this what you've been looking for?
B
137
S
33
G
17
Posts: 1,560
Reputation: 20,802

Post » Sun Mar 13, 2016 2:10 pm

@glerikud it seems to be working but when i exit my game and launch it again all levels are locked again.
B
10
S
1
Posts: 93
Reputation: 722

Post » Sun Mar 13, 2016 5:49 pm

Export it with NW.js and try the exported version. Is that still the case?
B
137
S
33
G
17
Posts: 1,560
Reputation: 20,802

Post » Sun Mar 13, 2016 9:13 pm

@garyrossiter - Maybe you can use an array to unlocking levels.

Firstly, when a level is complete, store a data in an array using Set at X action. Like this:

Array: Set at X:
X = Current level number
Value = 1

Secondly, store the array data as JSON inside the Local Storage using Set Item action:

Local Storage: Set item:
Key: "level"
Value: Array.AsJSON

Thirdly, at the level selection screen, retrieve the array data from the Local Storage:

System: Start of layout:
|-- LocalStorage: Check item "level" exists

LocalStorage: On item "level" exists:
|-- LocalStorage: Get item "level"

LocalStorage: On item "level" get:
|-- Load from JSON string LocalStorage.ItemValue

Finally, use a loop with the array once loaded, you need a "button" sprite with a number of frames and a Boolean variable:

INFO: Place these events inside the On item "level" get event!
System: For "level" from 1 to <the total number of levels>
== Array: Value at (loopindex) = 0
=== ButtonSprite: Anmation frame = loopindex
=== | -- ButtonSprite: Set lock to true

I hope this works. :D
Twitter | Facebook | Instagram

If you play Puyo Puyo games, you can meet me at the Puyo Puyo English Community Discord: https://discord.gg/0k41S8ARwvY2iTIQ
B
104
S
24
G
11
Posts: 698
Reputation: 12,935

Post » Mon Mar 14, 2016 12:46 pm

If you can, use @Tetriser 's version. It's a more flexible way of handling this. :)
B
137
S
33
G
17
Posts: 1,560
Reputation: 20,802

Post » Sat Mar 19, 2016 10:42 am

glerikud wrote:If you can, use @Tetriser 's version. It's a more flexible way of handling this. :)

No I very bad at arrays I use to di it fine with webstorage plugin but they changed it. is there a way to get webstorage back?
B
10
S
1
Posts: 93
Reputation: 722

Post » Sat Mar 19, 2016 12:59 pm

It's basically the same if you use LocalStorage. But if you really want to stick to a deprecated feature, then just right click in the object selection window and select show deprecated plugins.
B
137
S
33
G
17
Posts: 1,560
Reputation: 20,802

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 13 guests