How do I Create Multiple Doors With Individual Switches?

  • 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

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • I guess with 4 doors I would also use the UID to identify the doors and switches.

  • Works like a charm! Thanks guys!

    Here's the setup for everyone's future reference

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)