Course Index Section Start Previous Slide Next Slide 15

Basic Building Blocks for Reactive content

Task: Detect the user's entry into the world

Method: a "run once" script and a TimeSensor

#VRML V2.0 utf8
Group {
  children      [
    DEF enterWorldTimeSensor TimeSensor {
      cycleInterval     1
      enabled   TRUE
      loop      TRUE
      startTime 1
      stopTime  0
    }
    DEF enterWorldScript Script {
      eventOut      SFTime      startTime
      eventOut      SFBool      firstTime
      eventIn       SFTime      triggerIn
      url "vrmlscript:function triggerIn(value, time) {                                                             
         // fires exactly once by shutting off TimeSensor                                     
         startTime = value;
         firstTime = FALSE;
       }"
    }
  ]
}
# firstTime gets set to FALSE which disables TimeSensor
ROUTE enterWorldScript.firstTime TO enterWorldTimeSensor.set_enabled
ROUTE enterWorldTimeSensor.time TO enterWorldScript.triggerIn