Specifying object instances.

This forum is currently in read-only mode.
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Is there a way to make one instance of an object control a specific instance of another? Like a switch that opens a door. Or do I have to make each switch and door a separate object with separate events?

    Thank you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Apart from the family trick (that I never really got^^) you can always work with variables:

    + MouseKeyboard: Mouse is over Sprite

    + System: Sprite ('pid') Equal to 2

    -> System: Set global variable 'toOpen' to 1

    + System: Is global variable 'toOpen' Different to 0

    ++ Sprite: Value 'pid' Equal to global('toOpen')

    --> Sprite: do whatever needed to open the door

    ++ empty condition

    --> System: Set global variable 'toOpen' to 0

    One sprite with several instances. They all share a private variable named "pid", which is set to 1 for the first instance, 2 for the second, and so on. If you setup the pid wisely, you can simplify the first event. For example you could give all switches the lower numbers, and all doors numbers + 10 (or whatever many doors you have) So a switch with pid 2 belongs to door with pid 12, 3 belongs to 13, etc.

    Then the first event would read:

    + MouseKeyboard: Mouse is over Sprite

    + System: Sprite ('pid') Lower or equal 10

    -> System: Set global variable 'toOpen' to Sprite ('pid') + 10

  • You can have private variables for the Switch and Door objects (one of each, then place lots of them in the layouts) to pair them.

    Then compare this in the events Eg:

    For each Door

    -Subevent> Switch value "DoorNum" = Door.value("SwitchNum")

    You can then use different animation frames for different door and switch images and change this in their properties, or use a variable again to set it in-game.

    Edit: Ah, just saw Tulamide's post. Nice solution!

    Double edit: Oops, I just realized containers and an "On" variable on the Switch will probably work here too! <img src="smileys/smiley9.gif" border="0" align="middle" /> That's probably the easiest method, just have Switch in the container of Door and then:

    For each Door (or Switch, shouldn't matter which is looped through)

    -Subevent> Switch value "On" = 1, open door

    -Subevent> Switch value "On" = -1, close door

    Then, when the player uses a switch, just change its value of "On" to "On * -1"

  • Thanks a lot for the tips guys, I it goin now.

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