Scripting Basics

on this page: script template | eventIn functions | outgoing events | global vs. local scripts

Find it: Click the Script Editor button on the Action palette:

You'll need some programming knowledge to use the Script Editor, and you need to understand VRML as well. With this tool, you can create scripts written in VrmlScript, a platform-independent programming language.

Script Template

Use the Fields: Add button to specify the basic components of your script, which can be any number of the following:

Each eventIn has an associated function with the same name inside the script. When an eventIn is sent to the Script node with a new value, this function is called and the new value for the event is passed in.

First, you specify each eventIn, eventOut, and field with the Add button. Field and event names must be unique within the script. When you press Edit Script, the Script Editor creates a template file with the events and fields you specified, as well as a template function for each eventIn.

You fill in the rest of the template, including the eventIn function code and any other necessary code, using your favorite text editor. The Script Editor takes care of adding the Script node that contains your script to the scene file.

eventIn Functions

Every eventIn has two predefined arguments: a value and a time. The value is the new value of the incoming event. The time is a time stamp, of type SFTime. When you edit the script, you can change the name of these arguments. If you use only one argument, it is assumed to be the value.

Outgoing Events

An eventOut is simply a piece of data that the script sends out along a route. It does not have an associated function within the script.

Global vs. Local Scripts

The left panel of the Script Editor allows you to create and name both global and local scripts. Global scripts are scripts located at the root of the scene and are not associated with any object. Local scripts are associated with a particular object or group of objects. If the object is cut and pasted into the scene, the local script follows along with its associated object.To create a local script, first select the object to which the script is to be attached. You can create global scripts at any time, regardless of whether objects in the scene are selected.

Jump to: