Routes in VRML

Routes are a very important component of VRML. Basically, a route links an eventOut field to an eventIn field. Whenever the eventOut field changes, its value is sent to the eventIn field. This is very useful where you want to trigger a change in the world when the user performs an action.

For instance, you could create a script that will turn on a lamp when a light switch is touched. The following code will do this:

# code for lightswitch, attach sensor as child
DEF mysensor TouchSensor {}

# LargeLampType defined using PROTO and EXTERPROTO
DEF mylamp LargeLampType{}

ROUTE mysensor.isActive TO mylamp.turnmeon
Given that you create the lightswitch and the lamp, you can wire the output of the Touchsensor to the input of the lamp. When you touch the light switch, the boolean value of the state of the light switch will be sent to the lamp. If it is true, the lamp will turn on.