Cascading Timers

Sometimes you want to program several events to happen in a sequence. You can do this using multiple timers, by setting up the back or end event of one timer to trigger the start message of another.

This more advanced example builds on the Opening a Door example. The door is controlled by a timer node which animates it opening; this timer is started by a pointAtTrigger, so the door will begin moving when you click on it.

Additionally, there is now a room behind the door with a separate light; after the door opens, the outside light fades to black, and then the red light inside the room fades in. This is done by cascading the three timers together.

/*
	door_animated.scene
	an example demonstrating chaining timers together to make complex 
	sequences of motion
	
	point at the door and click to make it open
	after it swings open, the outside light fades out
	after that, the inside light turns on
	
	so, the chain of events is
	
	pointAtTrigger -> door_animator -> light1_animator -> redlight_animator

		
	note the initial value of the redlight node - it has a color of -1 -1 -1!
	this is a "negative light" or "darklight" - it sucks light out of the scene.
	it's used here to make the inside room dark to begin with; lights travel 
	through walls,
	so the outside light would initially illuminate the inside room.

	bcchang 04/04
*/
#include "User0"

light light1 (position(0 0 10 1))
object (file("wall.b3d"),position(0 10 0))

pointAtTrigger (when(button1,door_animator.start))
{
	object door (file("door.b3d"),position(0 10 0))
}

timer door_animator (duration(3),startValue(0),endValue(45),
			when(changed,door.orientation(0 0 $value)),
			when(back,light1_animator.start))

timer light1_animator (duration(5),startValues(1 1 1),endValues(.3 .3 .3),
			when(changed,light1.diffuse($value $value1 $value2)),
			when(back,redlight_animator.start))

object (file("whiteroom.b3d"),position(0 19 0))
light redlight (position(0 15 3 1),diffuse(-1 -1 -1))

timer redlight_animator (duration(5),startValues(-1 -1 -1),endValues(1 0 0),
			when(changed,redlight.diffuse($value $value1 $value2)))


(c) Ben Chang