data['title']); if($title_nice != "Main Page") { echo "

"; echo $title_nice; echo "

"; } ?>


Scripting allows a level to become dynamic. You can change physic settings, move objects, modify game logic, etc. A script is written in the Lua language and can be included in a level file.

Documentation about Lua can be found here :

To write a script, you needn't know a lot about the level files. Just use Inksmoto, where you can easily add your own script files. For doing this, you need to create a simple text file, where the functions you wanna use are put. In Inksmoto Level Editor, just give the path to this text file, in the field 'lua script' (you can find it in the level properties tab). A simple example for such a text file looks like this:

zone1 = {}

function OnLoad()
  return true;

function zone1.OnEnter()

Since 0.3.0, xmoto supports multiplayers ; in the script, a player is defined by an index. The first player has the number 0, the second the number 1, ...

The script examples on this page will use this basic level file:

<?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 easily with the Inksmoto level editor. It 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 that can execute actions when the player is inside.

Some functions require a minimum X-Moto version to work. If you use one of these functions, please put this information in the level. For example, to make your level require X-Moto version 0.2.0, add this line to your level:

<level id="tutscript" rversion="0.2.0">


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

This page was last modified on 26 November 2010, at 11:19. This page has been accessed 3,852 times.


Copyright © 2006