Two door switches (Solved)

Maniacus

  • Posts: 69
I have a switch using the attached behavior to open a door.  I would like to also have it be where 2 switches have to be activated to open the door. I also attached the doors behavior. How would I do this with my code? Thanks

« Last Edit: May 10, 2015, 09:55:08 pm by Maniacus »

t4u

  • Posts: 418
Really strange code...

Firstly you shouldn't check animation check in always clause -> use it in switch behavior. Use of globala variable makes me feel bad/angry/sad as well.

Back to your problem:

[Easy solution]
Makes a lot of mess when you want to have many doors and switches in single scene.

On start: number of active switches =0

In switch behaviotr when hitting the player
 If switch (not open) -> switch = open, number of active switches +1

If number of active switches == number of siwtches in scene -> open door

[Better solution]

Door behavior:
- list of switches that are required to be opened for door to open
- custom event : check if all <my> switches are open, i f yes then open myself

In switch behaviotr when hitting the player
 If switch (not open) -> switch = open, trigger custom event in door behavior of door that thsi swithc belongs to (check if all switches are open)

In this solution door is a parent object that creates switches. Switches know who is their parent (so they can ask the proper door for check) and parent (door) knwo all switches (list) in order to ask them if all of them are open.

[Easy solution] -> works if you have one door in scene (It would work with 2 as well, but with 3 it would be a mess).
[Better solution] -> always works but it can be pain in the ass since switches must be declared form code not from scene c4reator
USE PICTURES WHEN YOU ASK SOMETHING!
If I helped you be sure to mention it in your game.

Tutorials + downloads:
http://t4upl.blogspot.com/

Maniacus

  • Posts: 69
Thanks for your help. I believe i got the code right from what you told me.   If my code is correct i think that if to much time is spent touching the switch it jumps to 2 active switches, which opens the door.  What can i do to stop that? I plan to use no more than 2 switches and only 1 door in a scene.

Maniacus

  • Posts: 69
I figured it out. Thanks again  :)