Scripting in VRML

Most VRML browsers support some level of scripting in the VRML code. For instance, the SGI cosmo browser supports Java scripts, JavaScript scripts, and VrmlScripts. Scripting is very useful because basic VRML code does not support any kind of logical operators or any method to make decisions while the code is running. Embedded scripts allow the designer to add intelligence to VRML so that the user is not interacting with a static environment. Scripts can be used to add intelligence to monsters in a dungeon, to control animation, and to make decisions based on the input of the user. In the walkthrough example world, Vrmlscript scripts were used as boolean operators to control the opening and closing of the skylights and to control the animation of the sun across the sky.

A script in VRML is constructed like this:

Script {
	eventIn SFBool set_boolean
	eventOut SFBool set_out
	url "vrmlscript:
		function set_boolean(a,b)
		{
			if(a)
			set_out = true;
			else 
			set_out = false;
		}
	"
}

The above code sets up variables the script can use: an eventIn boolean and a eventOut boolean. The set_out boolean would then be routed to the eventIn of another object.