Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 3 (modified by bknecht, 16 years ago) (diff)

Scripting

Orxonox uses Lua for its scripts. Scripts are code pieces which add another layer to the game logic. As a Gamer you know those events which happen, when you reached a certain level or entered a room or area with your character. Those events are most certainly produced with a script engine like ours.

Our script engine has access to all objects in the game and are therefore quite powerful and easy to use, as you may see in examples.

There are two applications for the Orxonox scripting engine.

Level files

Our level files are pure XML-code. We add objects and ambient lights with XML tags and specify their parameters with attributes.

If your using the special lua tags <?lua and ?> you can create levels easier. You could use loops to generate more objects and you can let a level depend on earlier accomplishments of the player. If you use random parameters you can even create a level which looks slightly different every time a player plays it. Here some examples how you could use Lua in our level files.

Example: Asteroid field

As I write this wiki page we have a level with 226 asteroids in it. For each asteroid we need one line of XML code:

...
<Model position="-9613,-4258,4537" scale="103" mesh="ast1.mesh" rotationAxis="0.820812,0.60695,0" rotationRate="13" />
<Model position="-6169,19264,-4878" scale="69" mesh="ast3.mesh" rotationAxis="0,0.585115,0.235653" rotationRate="32" />
<Model position="8717,-16685,9115" scale="37" mesh="ast4.mesh" rotationAxis="0.0512168,0.899599,0" rotationRate="15" />
...

With the scripting engine we could generate those asteroids a lot easier:

<?lua
for i = 1, 226, 1 
do ?>
<Model position="<?lua print(math.random(-19597, 18732))?>,
 <?lua print(math.random(-19597, 18732)) ?>,
 <?lua print(math.random(-19597, 18732)) ?>" scale="<?lua print(math.random( 20, 119)) ?>"
 mesh="ast<?lua print(i%6 + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>,
 <?lua print(math.random()) ?>, <?lua print(math.random()) ?>
 " rotationRate="<?lua print(math.random(16, 44)) ?>" />
<?lua 
end
?>

This will randomly arrange asteroids of different look and rotation axis and speed in an area. In fact you can code any Lua you want according to the Lua-Manual. To actually add something to the XML-output you can use the print function. The above example shows you best how this works.