Locked / Unlocked Levels

Get help using Construct 2

Post » Fri Mar 16, 2012 11:01 am


I'm trying to figure out how to create menu with locked / unlocked levels.

I'm using WebStorage to store and autoload "AvailableLevel" global number.

Now, where's the catch.

I'm having 5 sprites (5 levels), and on top of them 4 instances of "locked" sprite.

I've tried destroying them lock levels by UID, but as I do not know exact UID of object it's a problem.

I've tried by setting up instance variable, but I cant set
Instance 1 - have instance variable value = 1
Instance 2 - have instance variable value = 2


I've tried by "System pick Lock instance 0,1,2,3,4 - Lock Destroy" and this is closest to working, but for strange reason at one point it destroys 2 locks not only 1 and I do not understand why..

What's correct approach.

Idea is to have 22 levels, and I need to know exactly which "locked" sprite instance is which one (by number) in order to create groups and paths.

Eg. when 1,2,3 are resolved, you get option to play 4 (not 5 and 6), 7 (not 8 and 9) .... like you will have path that you can follow, and then it splits in two and you can choose where to go, what to play.

I could resolve it by creating 22 times same locked sprite, but I do not find it as "best approach".

Tnx for any suggestion!
Posts: 17
Reputation: 461

Post » Fri Mar 16, 2012 11:32 am

Ok, as usual when u are fed up and ready to give up, it means you are closest to solution. :)

I just figured out that I can set value for each instance of lock manually (<varies>), and then easily "Lock value=AvailableLevel: Lock Destroy" ...

Don't know if this is the best approach but works fine now :)
Posts: 17
Reputation: 461

Post » Fri Mar 16, 2012 11:41 am

You need a parenting system.

Basically for your 'lvlSprite' (sprite representing the levels), you create 2 instance variable
'ID' and 'parentID'

Then at edit time you set each variable logically.
- 'ID' can be the number of the level (1-based)
- 'parentID' should be the ID of the level you have to clear to be able to play this one. 0 for the first level. (this system won't support multiple parent, just simple branching)

And then you'd just have to know which levels are cleared
(damn bit masking would make all that so much easier... there's a bit plugin by the way... but the concept might seem a lil bit complicated even if it's not. And also custom plugins aren't arcade-compatible)

Anyway storing cleared level is the hardest part. I would use a global text with the list of cleared levels

[code]Global text clearedLVL = ":0:"
Global number lvlID = 0
System: On start of layout
-> lock: destroy
System: foreach lvlSprite
System: find(":"&lvlSprite.parentID&":") = -1
    -> lvlSprite: spawn lock[/code]
And when you enter a level
[code]Mouse: on left click on lvlSprite
[invert]Mouse: is over lock
-> set lvlID to lvlSprite.ID
-> go to layout (by name) "level"&lvlID[/code]
And when you clear a level
[code]On level cleared
-> set clearedLVL to clearedLVL&":"&lvlID&":"[/code]

This way you'll build a string of level that will look like
We have that kind of separation to avoid problem with the find() function.

That's all
Yann2012-03-16 11:44:33
Posts: 1,479
Reputation: 16,336

Post » Fri Mar 16, 2012 12:11 pm


Sound like good way, I'll see if I'll use it.

I have problems now with lock, [invert]mouse over lock performs action every time and it should not...
Posts: 17
Reputation: 461

Return to How do I....?

Who is online

Users browsing this forum: mindragon73 and 3 guests