VastScript

Introduction

Look! It's moving. It's alive. It's alive... It's alive, it's moving, it's alive, it's alive, it's alive, it's alive, IT'S ALIVE!

Scripting in VastPark is currently achieved via the scripting language Lua.

Taken from the lua.org website:

“Lua is a powerful, fast, light-weight, embeddable scripting language. Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping. 'Lua' means 'moon' in Portuguese and is pronounced LOO-ah.”

All standard Lua language constructs are available from within VastPark, with the exception of the os and file libraries for security reasons.

If you are new to Lua, a good place to begin learning is over at the tutorials on the lua-users wiki: http://lua-users.org/wiki/TutorialDirectory.

Alternatively, for the full documentation visit http://www.lua.org/manual/5.1/

Conventions

VastScript extends Lua to provide additional functionality developers are likely to find useful when developing immersive spaces.

Case Sensitivity

All VastScript objects and reserved words are lowercase. Using incorrect case will result in a script error or possible logic error. In general its recommended to use lowercase for all scripting except where referencing elements by name.

Retrieve an element in the document context with name "theElement".

Correct:
--correct casing of the name of the element

scene:getelement('theElement')

Incorrect:
--incorrect casing of the name of the element

scene:getelement('theelement')

Set a value to true

Correct:
--using correct lower-case true

scene:getelement('timeline').enabled = true

Incorrect:
--using incorrect casing of true. Note in this case that True will actually be converted to the boolean representation of nil, which is false!

scene:getelement('timeline').enabled = True

Function Signature

Each script is expected to contain the following signature:

1 function main(obj, args)
2     --perform script logic
3 end

The parameters to the function may be named as desired, but the name of the function must be 'main'.

Script Execution Data

When executed, a script is provided with data related to the event that triggered invocation of it.

Mouse Events

Includes: MouseClick, MouseDown, MouseEnter, MouseHover, MouseLeave, MouseUp

param1 (obj)
The ImmlElement object associated with the mouse event

param2 (args)
The associated EventData object with the following properties:

EventType
The type of event that has occurred.

Data
The data associated with the event

Collision Events

Includes: Collided

param1 (obj)
The ImmlElement object associated with the collision event

param2 (args)
The associated EventData object with the following properties:

EventType
The type of event that has occurred.

Data
The data associated with the event

h4. Network Events
Includes: NetworkCustomMessage, NetworkConnectionEstablished, NetworkConnectionDropped

param1 (obj)
The ImmlElement object associated with the network event

param2 (args)
The associated EventData object with the following properties:

EventType
The type of event that has occurred.

Data
The data associated with the event

Load Events

Includes: Loaded, Unloaded

param1 (obj)
The ImmlElement object associated with the load event

param2 (args)
The associated EventData object with the following properties:

EventType
The type of event that has occurred.

Data
The data associated with the event