Scripted levels

From X-Moto
Revision as of 17:29, 15 August 2006 by Nadenislamarre (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


The scripts allow to a level to become dynamic : change some physic settings, move objects, ... A script is written in the Lua language and can be included in a level file.

To write a script, you must know a little about a level file. It is an xml file. It includes somes properties like the name of the level, it's description, ... Moreover, it includes blocks' and sprites' definitions. A block is composed of vertex which are the points to link to draw polygon.

To present the way to write a script, the simple following level example will be used :

<?xml version="1.0" encoding="utf-8"?>
<level id="tutscript">
<limits left="0" right="50" top="30" bottom="0"/>
<block id="Block0">
<position x="0" y="0"/>
<usetexture id="default"/>
<vertex x="5" y="5"/>
<vertex x="5" y="10"/>
<vertex x="10" y="10"/>
<vertex x="10" y="5"/>
<entity id="MyPlayerStart0" typeid="PlayerStart">
<size r="0.4"/>
<position x="7.5" y="10"/>
<entity id="Strawberry0" typeid="Strawberry">
<size r="0.4"/>
<position x="20" y="0.5"/>
<entity id="SnowMan0" typeid="Sprite">
<param name="name" value="SnowMan"/>
<position x="19" y="0.2"/>
<param name="z" value="-1"/>
<zone id="Zone0">
<box left="40" right="50" top="5" bottom="0"/>

This level can be made easyly with the xmoto level editor. It mainly includes a block called Block0 which is a square, a strawberry called Strawberry0 and a zone called Zone0. A zone is an invisible part of the level to execute actions when the player is around it. Some functions require a minimum xmoto version to work ; if you use one of these function, please put this information in the level like it : <level id="tutscript" rversion="0.2.0">.

Scripted level.jpg

All the code of the script is written in Lua. You can found the syntax here. However, if you choose to include the script in an xml file, < and > symbol must be replaced by < and >. The code of the script can be included between <script> and </script> in the level file.

Functions called by XMoto