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

Get help using Construct 2

Post » Mon Oct 21, 2013 2:06 pm

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?
B
19
S
5
Posts: 80
Reputation: 1,383

Post » Mon Oct 21, 2013 2:32 pm

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 partmindfaQ2013-10-21 14:35:02
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: 787
Reputation: 3,786

Post » Mon Oct 21, 2013 2:34 pm

You could use variables for the switches. Then conditions to make the door "open"
B
5
Posts: 13
Reputation: 305

Post » Mon Oct 21, 2013 2:37 pm

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.
B
19
S
5
Posts: 80
Reputation: 1,383

Post » Mon Oct 21, 2013 2:38 pm

You could give them both the same instance variable. So

on switch touched
for each door
door compare instance variable = switch.variable
- open door.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Oct 21, 2013 2:44 pm

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!
B
19
S
5
Posts: 80
Reputation: 1,383

Post » Mon Oct 21, 2013 4:48 pm

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
B
19
S
5
Posts: 80
Reputation: 1,383

Post » Mon Oct 21, 2013 5:09 pm

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.
B
11
S
2
Posts: 87
Reputation: 1,112


Return to How do I....?

Who is online

Users browsing this forum: NN81, ultrafop and 31 guests