Scripts in VRML
n241.tplt
Justification
Not enough interpolators
variable conversion
complex interactions
Not enough interpolators built into VRML
float to string?
translation to rotation?
Y rotation to Z rotation?
Circle interpolator?
More complex interactions
conecting switches
H2oComp
Light switch demo
Elements of the script node
eventIns
eventOuts
fields
url
eventIn
Name convention: set_something
Syntax: eventIn type name
Example: eventIn SFBool set_status
Receives values, triggers event
function with same name as eventIn
value passed as a parameter to function
eventOut
Name convention: something_changed
Syntax: eventOut type name
Example: eventOut SFBool status_changed
most scripts will assign value to eventOut
eventOut looks like a variable to script
the function's output is eventOut(s)
field
Name convention: any name
Syntax: field type name
Example: field SFInt32 count
Example: field SFNode output USE textbox
URL
points to script
javaScript .js file
java .class file
"javascript: multiline quote
Using inline JS scripts
Multiline quote
use ' or \" inside script
easiest way for simple scripts
Our preferred technique
Organization of a script
Function corresponding to each eventIn
function will have two parameters,
Example:
eventIn SFBool value_changed
url " javascript:
function value_changed(val, time){
//code goes here
} // end function
"