Author Topic: Eventing Tutorial - How to make a door automatically close behind you.  (Read 385 times)

Add these two events to the door:
[ x ] [ 0 ] onPlayerTouch -> Self-> cancelEvents
[ x ] [ 1000 ] onPlayerTouch -> Self -> door -> Close

It is important that the events are listed in that order.

Here is how it works.

The door is open.  A player steps inside of the door's bounding box(The space taken up by the door if it were just a box).
cancelEvents is triggered first
  • It does nothing, since there are no scheduled events to cancel.

door -> Close is triggered, with a delay of 1000 milliseconds.
  • This means that it is 'scheduled' to occur after 1 second.


After ~230 ms onPlayerTouch is triggered again.
cancelEvents is triggered first
  • All events scheduled by the brick are canceled, and will not occur.
  • This includes the door -> Close event we scheduled earlier.

door -> Close is triggered again, a with a delay of 1000 ms.
  • This means that it is once again 'scheduled' to occur after 1 second.


This behavior will repeat until the player steps away from the door.
At that point the door -> Close that was scheduled in the last iteration will be allowed to occur, since- it is no longer being canceled and restarted.