Unlocking Doors through different layouts

Get help using Construct 2

Post » Mon Apr 07, 2014 11:23 am

Hello,

Might be a beginner question..

I use several Layouts.
They are sometimes connected with doors (1 layout can have from 1 to 4 doors - leading to 1-4 differents layouts).
The player can also go back to any previous layouts if he wants to.

If a door is unlocked/open from the start, no problem as it will always be open.

But if it's locked and the player has to unlock it then I got a problem.

Because if the player unlocks it, proceed to the next layout, and suddenly decide to go back to the previous layout, that door is locked again.
How do I keep that door open/unlocked when reloading its layout ?
I'm sure it's with the help of Global variable....but I cant find a proper solution..

Any help would be appreciated, thanks ! :)


Edit: also all the layouts share 1 single event sheet, so I would like to keep it like that if possible.
Lunar Mission for Android & iOS
B
16
S
2
Posts: 44
Reputation: 1,365

Post » Mon Apr 07, 2014 12:33 pm

Extremely in depth Tutorial

Simle answer. Store in global variables or webstorage etc.
So door1 = 0 (locked)
player unlocks
door1 = 1 (unlocked)

If door1 = 1
do something etc etc
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,708

Post » Mon Apr 07, 2014 1:31 pm

Thanks Dutoit, that tutorial is nice but it uses arrays for storing the doors states...and I dont use arrays :/

Im still trying to figure out how to store the doors differents states using global variables...like you said.

Lets say the Level_1 Door is locked.
There is 1 key in this Level.
Once the key has been picked up, the door is unlocked
Level_2 is now available (and you can go back to level_1 (now unlocked) from there.

The lock mechanics I'm using is as follow:
Door boolean = "locked" (=solid)
Player pickup key -> Door: Set boolean to "unlocked" "(=not solid)

But how do I store this in a global variable ? that's where my brain is stuck...

I believe I need a global variable for each doors ?
So something like
Door_1= 0 (locked)
Door_1= 1 (unlocked)

And so on for door_2, 3, etc

But how do I link theses global to the appropriate door/layout ? (using a single event sheet and a single door object...which is/will be instanced)
Lunar Mission for Android & iOS
B
16
S
2
Posts: 44
Reputation: 1,365

Post » Mon Apr 07, 2014 2:36 pm

Think of it like that.
System> compare variable 'Door_1' > if = 0> door1.solid = true(door locked)
else door1.solid = false( door unlocked).
Just do that for all your doors. Have you tried it? What's exactly your problem, isn't it working or you are having trouble making the logic?
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Mon Apr 07, 2014 2:46 pm

It's hard to explain,

Basically I have 1 object (the door) and 1 global variable to store the lock/unlock state through all layouts.
But I dont know how to link the object (door) to the global variable without having to create multiple objects/doors instead of using instances.

I have found a solution...which is to create an additional event_sheet for each layout that has a key/door mechanism in it...that's certainly not the best solution...but it works so far...so...
But Still if anyone got a better solution (and is able to understand my poor explanation :D ), I'd be glad to hear it ! :)
Last edited by johnsmith on Mon Apr 07, 2014 2:53 pm, edited 1 time in total.
Lunar Mission for Android & iOS
B
16
S
2
Posts: 44
Reputation: 1,365

Post » Mon Apr 07, 2014 2:52 pm

johnsmith wrote:Thanks Dutoit, that tutorial is nice but it uses arrays for storing the doors states...and I dont use arrays :/


I suggest you start using arrays or at least dictionary.
Game have lots and lots and lots of data, and you can't store everything into variables.
Think 100's of variables and the nightmare it becomes.
Anyways, caiorosisca gave great explanation.

Edit: You don't have to create new event sheet each layout. Create 1 event sheet. And include it into each layout.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,708

Post » Mon Apr 07, 2014 3:07 pm

DUTOIT wrote:Edit: You don't have to create new event sheet each layout. Create 1 event sheet. And include it into each layout.


Yeah but then my problem would be the same.....I dont know how to manage multiple layout/doors linked to global variables.
Here's my separated event_sheet (for the level_1) if you want to take a look:
Image

This is how I managed to apply this mechanism to multiples doors/layout...but as I said, not the best solution I guess.

I think I know what caiorosisca means, but what I'm asking, is how to store the doors state in beetween layouts...

I'm gonna take a look at the dictionary, hopefully I will get something better from it :)
Lunar Mission for Android & iOS
B
16
S
2
Posts: 44
Reputation: 1,365

Post » Mon Apr 07, 2014 3:16 pm

If you are looking for the a better way, global variables really isn't your answer, as DUTOIT said, I would go with a dictionary.
It isn't hard to understand at all, even if you never used it. A dictionary is a list with 2 colluns, imagine something like that
key value
"key1" 2
"banana" 5
"green" 3


basically you can store anything on it, and if you check the value for banana for example, it will be 5.
Now back to your door, you can use only one instance of the door, create an instance variable on it ( I would go for something like "doorNumber"), so each door will have it's number.

Your dictionary would look like this:

"door1" 1
"door2" 0
"door3" 0

The key part(left one) you would acess using "door"&Door.doorNumber. // Door would be the actual object, 0 means locked, 1 means unlocked (you can also use strings if you like, "locked"/"unlocked").

To check if the doors are locked or not, you can use:

Pick all "Door"> Dictionary, compare key> "door"&doorNumber, if equals 1(or "unlocked") set solid to false.
Let me know if I can help with something else(please tag me)
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Mon Apr 07, 2014 3:24 pm

That sounds very good, thanks for the explanation caiorosisca :)
I'll definately give this a try.
Lunar Mission for Android & iOS
B
16
S
2
Posts: 44
Reputation: 1,365

Post » Wed Apr 09, 2014 5:28 pm

Well well, looks like I have some troubles to achieve what I want with the dictionary...

As it's hard to explain for me, here is a little screenshot of my event_sheet:
Image

I'm not used to use "pick all", so it might come from that...Or the fact that I use both 2 objects's instance variables (the key, and the door) to call the dictionary's key "door_1" ?
(the door has a boolean "open" true/false wich is not in this event_sheet....but which is working correctly (or at least it was so I'm pretty sure it's my dictionary's event that has a problem)

Do you see what I'm doing wrong ?
Lunar Mission for Android & iOS
B
16
S
2
Posts: 44
Reputation: 1,365

Next

Return to How do I....?

Who is online

Users browsing this forum: Magistross, mtnboy22, Rable and 6 guests