How do I make events and actions target singular objects?

Get help using Construct 2

Post » Wed Aug 31, 2016 3:49 pm

I have a door sprite and an invisible TriggerBox sprite for said door, the door sprite has 2 frames: Open and Closed. When the character overlaps the invisible sprite, it launches an event which sets the door sprite frame to open and plays a DoorOpen sound. The door stays open, and the sound only triggers once.

All this works totally fine, but I have multiple instances of this Door/TriggerBox duo around my game; how do I make the event target the singular object that the character opens instead of all of them. At the minute, I'm testing it with two buildings that both use the Door sprite and invisible TriggerBox sprite for said door. But when I walk through one of them, it changes the animation frame for both doors.

The "Animation frame = 0" is just to make sure the door stays open when opened.

I thought that the "For each" event would actually do this, but I guess not. Any help would be greatly appreciated, thanks!

If you need a hand with anything, just drop me a PM.
Posts: 29
Reputation: 560

Post » Wed Aug 31, 2016 4:03 pm

That is a bitt a bizar construction.

There are two thing to consider when using a condition.

1/ The actions run if the condition is true.
2/ The actions adress the picked objects.

For 'each' picks an instance 1 by 1. If its animation frame = 0, it stays in the picklist, else it is filterd out. The overlapping condition does not filter anything doors out the picklist, the overlapping condition only makes the condition true or false. Conclusion: the action adresses each door with animation = 0, when character is overlapping any doorcollissionbox.

You need to pair doorcollissionbox with its door. To do that, use a containetr. Or give Door and its Collisionbox an instance variable (say 'pair') that you gave the same number. So instance variable 'pair' of the first door = 1, and the instance variable 'pair' of the first collision box = also 1.

Now you can ...

Condition: On doorcollissionbox overlapping Character (picklist contains now that doorcollissionbox & character)
Condition: Pick by comparisation ... Door.pair .. = .. doorcollissionbox.pair (add the right door the picklist)
Actions .... whatever you need.
Posts: 2,493
Reputation: 20,950

Return to How do I....?

Who is online

Users browsing this forum: FabianB, ST314 and 30 guests