Advanced:
Creating a Script From Scratch

This page offers a few guidelines on how to enter a script directly using a text editor. For a complete description of VRML syntax, see the VRML 2.0 Specification at http://vrml.sgi.com.

Field and Event Declarations

Fields and events are entered after the FIELDS line and before the BEHAVIOR line in the script template. The syntax is

interface_type   field_type   name

For example:

eventIn  SFBool     lightOn
eventOut SFRotation myRotat
field    SFColor    myColor   1 1 1

Fields must have an initial value specified, as shown in this example. Syntax for fields is the same as the file format syntax described in the VRML 2.0 Specification.

Functions

Following the BEHAVIOR line, add a function for each eventIn (if you want the event to do something). The form of the function is

function eventIn_name( value, time )
{
  // body of function //
}

The function can have one or two arguments. If it has only one value, it is assumed to be the value.

These functions can call other functions, which have the general syntax:

function function_name( arg1, arg2, ... )
{
  // body of function //
}

initialize() function

The initialize() function is called once when the world is loaded and before any events are processed. This function allows you to set up field values and eventOut values. This function takes no parameters. Events generated from it are given the time stamp of when the world containing the Script node was loaded.

shutdown() function

The shutdown() function is called when the world is unloaded. It allows you to deallocate memory and perform any other necessary clean-up. This function takes no parameters. Events generated from it are given the time stamp of when the world containing the Script node was unloaded.

eventsProcessed() function

You can define an eventsProcessed() function that will be called after some set of events has been received. Some browsers call this function after the return from each eventIn function, while others call it only after processing a number of eventIn functions. This function takes no parameters. Events generated from it are given the time stamp of the last event processed.

Click here to view a sample script.

Jump to: