Chapter 3. Scripting

Table of Contents

Introduction
The script node
Getting to grips with scripting
Available Lua Functionality
Example 1 - Moving objects in Lua
Code
Analysis
Example 2 - Randomly positioning objects
Code
Analysis

Introduction

Whilst it is possible to create a range of animations and interactions using action nodes, some more complex behaviours require the use of scripting. The framework makes it possible for you to write scripts in the Lua language that can manipulate your scene.

The script node

Scripts are included using the script node in scene files:

<script type="text/x-lua">
<![CDATA[ 
	-- Your Lua script goes here
 ]]>
</script>

Any code that is inside a script node but not inside a function is run when the target is first visible. Code that is inside a function will be run if you call it from Lua outside a function, or using the runscript action node.

Getting to grips with scripting

The pages that follow provide a number of examples that introduce the scripting environment. In addition, the following resources may be of use:

Available Lua Functionality

Most of the functions and libraries present in the standard Lua distribution and documented in the Lua manual are available for use in scenes. There are a number of exceptions.

Not available

  • the io library;

  • the debug library;

  • the package library;

  • the require command;

  • the dofile and loadfile functions;

  • a number of functions in the os library;

  • a arg object;