on this page: Quick Reference | Scripting Language | Example |
Find it: Click
The Script Editor allows you to define fields and events and create scripts that run within your scene. This editor also includes a button that allows you to create a sensor within the scene to trigger the script.
The script is written in VrmlScript, a lightweight, platform-independent programming language that is very similar to JavaScript. VrmlScript provides functions that are called when events come into the script, access to fields within the script, logic to operate on the fields, and the ability to send events from the script.
Here's a quick guide to the Script Editor:
Click image for full view.
A detailed description of VrmlScript can be found at:
http://vrml.sgi.com/moving-worlds/spec/vrmlscript.html
In Cosmo Worlds, the script itself is contained in the url field of the Script node, as a single string. The string must begin with vrmlscript: The script defines functions for each eventIn. Internal fields and eventOuts can be used as variables.
Here is a simple example of including a script node in a VRML file:
#VRML V2.0 utf8 DEF XFORM Transform { children [ Shape { geometry Cone {} }, DEF SENSOR TouchSensor { }, DEF SCRIPT Script { eventIn SFBool triggerIn eventOut SFFloat fractionOut field SFFloat fraction 0 url "vrmlscript: function triggerIn(trigger) { if (trigger) { fraction = fraction + 0.1; fractionOut = fraction; } }" }, DEF INTERP PositionInterpolator { keys [0.0, 1.0] values [0 0 0, 3 0 0] } ] } ROUTE SENSOR.isActive TO SCRIPT.triggerIn ROUTE SCRIPT.fractionOut TO INTERP.set_fraction ROUTE INTERP.outValue TO XFORM.translation
Jump to: Creating a Script