How do I "link" objects in the Layout editor?

0 favourites
  • 8 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi,

    I'm looking for a way to tie or link objects to other in the Layout editor.

    For example, let's say I have a Switch object and a Door object. I'm looking for a way to say "this switch is linked to this door".

    Something like this:

    Switch1 opens Door1

    Switch2 opens Door2

    Switch3 and Switch4 open Door3

    At first I was thinking of using the UID of the doors in a instance variable inside the switch, but I've read somewhere that the UID of objects can change everytime new objects are added in the Layout editor.

    Any advices?

  • instance variables, for example a switch could have "doorid" as variable. Set it to the UID of the door you want it to open.

    Then upon the event of the door to open

    door-open-condition

    door pick by unique ID = switch.doorid: open door

    this way only the door with the fitting ID is opened.

    If you need one switch to open more doors, use an array or give doors a specific switchID and then instead of picking by UID, pick doors by comparison door.switchid = switch.doorid

    Edit: if you dislike using the UID, use the instance variables on both door and switch to connect them like I explained in the last part

  • You could use variables for the switches. Then conditions to make the door "open"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well, that's what I wanted to do first, but I read elsewhere in the forum that UID often change when we add stuff to a layout. I wouldn't want to carefully copy paste the UID of all my doors into my switches, only to discover later that the UID of all my doors have randomly changed and I need to rewire them all...

    Also, just to help a bit, is there a good tutorial somewhere about how to work with UID (in general). I'm not sure I understand how "pick by unique ID" is supposed to work.

  • You could give them both the same instance variable. So

    on switch touched

    for each door

    door compare instance variable = switch.variable

    • open door.
  • Ah I see. You mean that I would create my own instance variables that would act as UID, but that I would control by hand.

    Man, it's so simple. Why didn't I think of that!

  • For those interested, here's how I did it:

    Instance variable "doorID" inside the door and "switchID" inside the switch.

    Event:

    Player: On collision with Switch

    System: For each Door (This is important, otherwise, it won't work)

    Switch: switchID = Door.doorID

    Action:

    set variable Door.open to True

  • I have a similar setup and did more or less the same thing (door has SwitchID variable that will hold switch's UID and vice versa), but I did an extra step to skip the tedium and error-proneness of entering all the IDs by hand.

    I made an invisible sprite called "linker" and placed it in my layouts connecting the switches to the doors. Then on layout start, I loop through all the linkers, pick the door and switch that it overlaps, and set the ID variables there.

    Then I delete the linker sprite since it's unused except at initialization. This was handy for me since I'm a more visual person, so being able to see in the editor which doors were linked to which switches was helpful.

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