How do I make this locked doors open

Get help using Construct 2

Post » Thu Jan 19, 2017 2:51 am

Hi, i want to make the locked door open 1 by 1 when the player push the right button.

Here's the example

There's a 1 sprite named locked door (red blue green) and each button to open the door with the same color
Image

When player steps on the first one (red button), the red door opens
Image

When player steps on the second one (blue button), the blue door opens
Image

When player steps on the third one (green button), the green door opens
Image

But when the player didn't push the button in the right order, the door will be locked again (red blue green)
B
41
S
21
G
27
Posts: 39
Reputation: 17,252

Post » Thu Jan 19, 2017 12:59 pm

Track the colour of the last-pressed switch by adding a variable to the player. A string-variable would work for this - we'll call it Player.LastButtonColour. You'll need another variable on the button to track what colour should have been pressed previous to it in the sequence - we'll call it Button.PreviousSequenceColour

When the player jumps on a button, check the Player.LastButtonColour against Button.PreviousSequenceColour. If they match, open the matching door, and set Player.LastButtonColour to represent the button's colour. If they don't match, re-lock all doors in the sequence.
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Thu Jan 19, 2017 11:36 pm

mrtumbles wrote:Track the colour of the last-pressed switch by adding a variable to the player. A string-variable would work for this - we'll call it Player.LastButtonColour. You'll need another variable on the button to track what colour should have been pressed previous to it in the sequence - we'll call it Button.PreviousSequenceColour

When the player jumps on a button, check the Player.LastButtonColour against Button.PreviousSequenceColour. If they match, open the matching door, and set Player.LastButtonColour to represent the button's colour. If they don't match, re-lock all doors in the sequence.


A string-variable? That's new to me. Can you create a .capx of how this would work?
B
207
S
116
G
8
Posts: 140
Reputation: 20,926

Post » Fri Jan 20, 2017 1:39 am

mrtumbles wrote:Track the colour of the last-pressed switch by adding a variable to the player. A string-variable would work for this - we'll call it Player.LastButtonColour. You'll need another variable on the button to track what colour should have been pressed previous to it in the sequence - we'll call it Button.PreviousSequenceColour

When the player jumps on a button, check the Player.LastButtonColour against Button.PreviousSequenceColour. If they match, open the matching door, and set Player.LastButtonColour to represent the button's colour. If they don't match, re-lock all doors in the sequence.


Ahh, i get it.
Thanks man! :D
B
41
S
21
G
27
Posts: 39
Reputation: 17,252

Post » Fri Jan 20, 2017 11:22 am

YoHoho wrote:A string-variable? That's new to me.


Objects can carry variables, which must be either number (float or integer), string (alphanumeric), or boolean (true/false) values according to a preset specified by the developer:

https://www.scirra.com/manual/73/instance-variables
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Fri Jan 20, 2017 11:22 am

hsetiawan wrote:Thanks man! :D


No worries, hope it works out :)
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Sat Jan 21, 2017 12:16 am

So... it's just an instance variable. OK.
B
207
S
116
G
8
Posts: 140
Reputation: 20,926


Return to How do I....?

Who is online

Users browsing this forum: jorgmaquoi, Yahoo [Bot] and 14 guests