How do I Create Multiple Doors With Individual Switches?

Get help using Construct 2

Post » Sat May 16, 2015 4:53 am

QUESTION ANSWERED (thanks!)

I am creating a Top Down Shooter and I have 4 doors that are opened by individual switches. I need for each switch to open a specific door. I attempted to have the switches compare their own variables to that of the doors, but all of the doors just opened at the same time.

I didn't want to create 4 individual doors and 4 individual switches, but until somebody gives me a better idea, that's what I am doing

NOTE: The doors FUNCTION properly, I just need to get the BUTTONS working properly

This is the layout, the doors are the tiny gray strips between the black lines
Image
Last edited by HerrVonClaussen on Sun May 17, 2015 2:49 am, edited 1 time in total.
B
7
S
1
Posts: 20
Reputation: 585

Post » Sat May 16, 2015 5:29 am

I take it that you are using a single door object and single button object for all four from the way you wrote it. If that's the case, there is a simple way of doing it. Every object will have a UID, it helps you identify every single object in the game, even if they are clones from the same object. When you select each individual object, notice that on the right properties layout, there will be a UID section which gives you their number. So all you need is to use this to achieve what you want.

Player is overlapping button: Set variable1 to button.UID

Variable is (17 example)
Sub event:
Pick Door with UID 20, (Let's say that 20 is the UID of the door you want button17 to open.)
Place your actions here to open the door.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Sat May 16, 2015 10:42 am

rekjl wrote:I take it that you are using a single door object and single button object for all four from the way you wrote it. If that's the case, there is a simple way of doing it. Every object will have a UID, it helps you identify every single object in the game, even if they are clones from the same object. When you select each individual object, notice that on the right properties layout, there will be a UID section which gives you their number. So all you need is to use this to achieve what you want.

Player is overlapping button: Set variable1 to button.UID

Variable is (17 example)
Sub event:
Pick Door with UID 20, (Let's say that 20 is the UID of the door you want button17 to open.)
Place your actions here to open the door.


But why would you use UIDs for that instead of adding an instance variable that works as identifier and makes your code a lot more readable, when you name your doors with some kind of logic.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Sat May 16, 2015 10:55 am

@mindfaQ, agreed, using instance variables are the best way to do this, definitely a best practice. But he said he tried and couldn't get it to work, so unless he is willing to share his capx, we can't see what is going wrong, so I gave him another workaround.

HerrVonClausson If you would like to make the instance variable method work, you could post the capx and we could have a look to see why it isn't working properly. As mindfaQ mentioned, it is definitely the more readable and professional way to go about it.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Sat May 16, 2015 10:57 am

I guess with 4 doors I would also use the UID to identify the doors and switches.
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Sun May 17, 2015 2:53 am

Works like a charm! Thanks guys!
Here's the setup for everyone's future reference
Image
B
7
S
1
Posts: 20
Reputation: 585


Return to How do I....?

Who is online

Users browsing this forum: 8tomo8, brunopalermo and 10 guests