To define the purpose of a level, you need to create rules for it. Rules describe what's allowed to be built in a level, what it takes to win, and can also be used to control objects within the game world.
Rules are formed from expressions, which can be either atomic or compound. Expressions are separated by white space (spaces, tabs, and new lines) and brackets. Atomic expressions are a single word. Compound expressions have one or more expressions as parameters in the form:
(function parameter1 parameter2 parameter3
… parameterN)
Parameters of compound expressions can themselves be compound expressions.
Units are kilograms, metres, and seconds (except time
, which is given in
milliseconds). Angles are measured in radians. The coordinate system is righthanded, with the y
axis pointing up. The rules are invoked every simulation step, 500 times a second.
Expression  Type  Types of parameters  Notes  

1  2  3  4  Extra  
Types  
booltype 
booltype  Boolean value (true/false)  
inttype 
inttype  Integer  
floattype 
floattype  Real number  
pointtype 
pointtype  3D point  
nodetype 
nodetype  
linktype 
linktype  
balltype 
balltype  
sheettype 
sheettype  
objecttype 
objecttype  link/ball/sheet  
weldjointtype 
weldjointtype  
gearedjointtype 
gearedjointtype  
differentialjointtype 
differentialjointtype  
curvetype 
curvetype  
targettype 
targettype  
motortype 
motortype  
materialtype 
materialtype  
contacttype 
contacttype  A pair of items.  
Variable declarations  
(const t v x) 
none  type  unassigned  t 
Declares v as a constant variable of type t , with value
x . Constant variables are initialised once and then always hold the same value. 

(static t v x) 
Declares v as a static variable of type t , initialised to
x . Static variables are initialised once and then maintain their previous value each
time the rules are invoked. 

(dynamic t v x) 
Declares v as a dynamic variable of type t , initialised to
x . Dynamic variables are initialised to the value of x each time the
rules are invoked. 

(const t (v n) x …) 
none  type  unassigned  t 
t 
Declares v as an array variable of type t with
n elements. x and any subsequent parameters are used to initialise the
elements – there must be either 1 or n initialisation parameters. If there is 1
then all elements are initialised to x . If there are n then each element
is initialised to the corresponding parameter. Arrays are indexed from 0, so the first element is
(v 0) and the last element is (v ( n 1)) . 

(static t (v n) x …) 

(dynamic t (v n) x …) 

(constloopinit t (v n) i x) 
none  type  unassigned  unassigned  t 
Declares v as an array variable of type t with
n elements. The elements are initialised to x for i ∈
[0, n ). So (staticloopinit inttype (a 4) i i) would initialise the
array a to (0, 1, 2, 3). 

(staticloopinit t (v n) i x) 

(dynamicloopinit t (v n) i x) 

Variables  
v 
type of v 
The current value of the variable v . 

(v i) 
type of v 
int  The current value of the i th element of the array variable v . Can be
used in place of a nonarray variable in the following expression definitions. 

Constants  
false 
bool  
true 

0 , 1 , 29 etc. 
int  
0.0 , 1.2 , 29.384 etc. 
float  
pi 
float  π  
2pi 
2π  
maxnumplayers 
int  The (maximum) number of players. Player indexes start from 0, forming the range [0,
numplayers ) – including 0 but not numplayers . 

numplayers 

numnodes 
int  The number of items.  
numlinks 

numballs 

numsheets 

numobjects 

numweldjoints 

numgearedjoints 

numdifferentialjoints 

numcurves 

numtargets 

nummotors 

nummaterials 

(numplayernodes p) 
int  int  The number of items for player p . p = −1 refers to
the level items – the things created as part of the level. 

(numplayerlinks p) 

(numplayerballs p) 

(numplayersheets p) 

(numplayerobjects p) 

(numplayerweldjoints p) 

(numplayergearedjoints p) 

(numplayerdifferentialjoints p) 

(numplayermotors p) 

metal 
material  
wood 

rubber 

super 

ice 

plastic 

damp 

rocket 

helium 

Ranges  
(interval x y) 
intrange  int  int  The range [x , y ) – including x but not
y . 

nodes 
noderange  The range of the items.  
links 
linkrange  
balls 
ballrange  
sheets 
sheetrange  
objects 
objectrange  
weldjoints 
weldjointrange  
gearedjoints 
gearedjointrange  
differentialjoints 
differentialjointrange  
curves 
curverange  
targets 
targetrange  
motors 
motorrange  
materials 
materialrange  
(playernodes p) 
noderange  int  The range of items for player p . p = −1 refers to
the level items – the things created as part of the level. 

(playerlinks p) 
linkrange  
(playerballs p) 
ballrange  
(playersheets p) 
sheetrange  
(playerobjects p) 
objectrange  
(playerweldjoints p) 
weldjointrange  
(playergearedjoints p) 
gearedjointrange  
(playerdifferentialjoints p) 
differentialjointrange  
(playermotors p) 
motorrange  
(group x y …) 
(type of x )range 
any  type of x 
type of x 
The range containing x , y , … 

(objectgroup x y …) 
objectrange  link ball sheet object 
link ball sheet object 
link ball sheet object 

contacts 
contactrange  The range containing all the pairs of items currently in contact.  
Conversions  
(float x) 
float  int  
(int x) 
int  float  Rounds towards zero, losing the fractional part.  
(intround x) 
Rounds to the nearest integer.  
(point x y z) 
point  float  float  float  (x , y , z ) 

(getx p) 
float  point  p _{x} 

(gety p) 
p _{y} 

(getz p) 
p _{z} 

(object x) 
object  link ball sheet 

(contact x y) 
contact  int link ball sheet object curve 
int link ball sheet object curve 
The pair of items. int parameters specify world boundaries, which have the range
[0, 5], corresponding to the left/right/bottom/top/back/front of the world space. 

Boolean operators  
(! x) 
bool  bool  ¬x 

( x y …) 
bool  bool  bool  bool  x ∨ y ∨ … 

(& x y …) 
x ∧ y ∧ … 

Relational operators  
(= x y) 
bool  any  type of x 
x = y 

(!= x y) 
x ≠ y 

(< x y) 
bool  int float 
type of x 
x < y 

(<= x y) 
x ≤ y 

(> x y) 
x > y 

(>= x y) 
x ≥ y 

Arithmetic operators  
( x) 
type of x 
int float point 
−x 

(+ x y …) 
type of x 
int float point 
type of x 
type of x 
x + y + … 

( x y …) 
x − y − … 

(* x y …) 
type of x 
int float 
type of x 
type of x 
x × y × … 

(/ x y …) 
x ÷ y ÷ … 

(* x y …) 
point  point  float  float  x × y × … 

(/ x y …) 
x ÷ y ÷ … 

(% x y) 
int  int  int  x mod y 

(~ x y …) 
type of x 
int float point 
type of x 
type of x 
mean(x , y , …) 

(<< x y …) 
type of x 
int float 
type of x 
type of x 
min(x , y , …) 

(>> x y …) 
max(x , y , …) 

(limitmin x y) 
type of x 
int float 
type of x 
max(x , y ) 

(limitmax x y) 
min(x , y ) 

(limit x y z) 
type of x 
int float 
type of x 
type of x 
min(max(x , y ), z ) 

(mag x) 
type of x 
int float 
x  

(sign x) 
1 if x is positive,−1 otherwise. 

(sq x) 
type of x 
int float 
x ² 

(sqrt x) 
float  float  √x 

(sin x) 
float  float  sin x 

(cos x) 
cos x 

(asin x) 
sin^{−1} x , in the range [−½π, ½π]. 

(acos x) 
cos^{−1} x , in the range [0, π]. 

(atan x y) 
float  float  float  tan^{−1} (y ÷ x ), in the range [−π,
π].Has no discontinuities if √( x ² + y ²) >
0. 

(interpolate x y z) 
type of x 
float point 
type of x 
float  x + z (y − x ) 

(smoothlimit x y z) 
float  float  float  float  z − (½(z − y ))² ÷
(x − y ) if x ≥ ½(y +
z ),y − (½(z − y ))²
÷ (x − z ) otherwise.Like (limit x y z) , but
with smoothed linearconstant transitions. 

(lensq p) 
float  point  p ² = p _{x}² + p _{y}² +
p _{z}² 

(len p) 
p  = √(p _{x}² + p _{y}²
+ p _{z}²) 

(distsq p q) 
float  point  point  q − p ² =
(q _{x} − p _{x})² +
(q _{y} − p _{y})² +
(q _{z} − p _{z})² 

(dist p q) 
q − p  =
√((q _{x} − p _{x})² +
(q _{y} − p _{y})² +
(q _{z} − p _{z})²) 

(norm p) 
point  point  p = p ÷ p  

(dot p q) 
float  point  point  p ⋅ q = p _{x}q _{x} +
p _{y}q _{y} +
p _{z}q _{z} 

(cross p q) 
point  point  point  p × q = (p _{y}q _{z}
− p _{z}q _{y},
p _{z}q _{x} −
p _{x}q _{z},
p _{x}q _{y} −
p _{y}q _{x}) 

(project p q) 
point  point  point  q ((p ⋅ q ) ÷ q ²)p projected on to q . 

Conditionals  
(? c x y) 
type of x 
bool  any  type of x 
x if c ,y otherwise. 

(if c a) 
action  bool  action  Executes a if c . 

(ifelse c a b) 
action  bool  action  action  Executes a if c ,executes b otherwise. 

Range tests  
(in x r) 
bool  any  (type of x )range 
true if x ∈ r . 

Loops  
(count r v c) 
int  anyrange  unassigned  bool  #v ∈ r  c 

(exists r v c) 
bool  anyrange  unassigned  bool  ∃v ∈ r  c 

(all r v c) 
∀v ∈ r  c 

(all+ r v c d) 
bool  anyrange  unassigned  bool  bool  (∃v ∈ r  c ) ∧ (∀v
∈ r  c ⇒ d ) 

(sum r v c x) 
type of x 
anyrange  unassigned  bool  int float point 
∑ x for all v ∈ r  c . 

(prod r v c x) 
type of x 
anyrange  unassigned  bool  int float 
∏ x for all v ∈ r  c . 

(mean r v c x) 
type of x 
anyrange  unassigned  bool  int float point 
mean(x ) for all v ∈ r  c . 

(min r v c x) 
type of x 
anyrange  unassigned  bool  int float 
min(x ) for all v ∈ r  c . If
¬∃v ∈ r  c then the largest representable
value. 

(max r v c x) 
max(x ) for all v ∈ r  c . If
¬∃v ∈ r  c then the smallest representable
value. 

(for r v a) 
action  anyrange  unassigned  action  Executes a for all v ∈ r . 

Assignments  
(++ v) 
action  intvariable floatvariable 
Increments the value of the variable v . 

( v) 
Decrements the value of the variable v . 

(set v x) 
action  anyvariable  type of v 
Sets the value of the variable v to x . 

(setwon p x) 
action  int  int  Sets player p won, with a score of x . x has the range
[−1, 1000]. x = −1 indicates that the level is not scored. 

(setlost p) 
action  int  Sets player p lost. 

(setauto x y) 
action  int  float  Sets the value of the automated input x to y . x has the
range [1, 16] and y has the range [−1, 1]. 

(setbroken x) 
action  link ball sheet object 
Sets x broken. 

(setposition x y) 
action  target  point  Sets x 's position to y (m). 

(setradius x y) 
action  target  float  Sets x 's radius to y (m). 

(setgravity x) 
action  float  Sets the gravity to x × normal gravity. 

(setairdensity x) 
action  float  Sets the air density to x × normal air density. 

Action combinations  
(do a b …) 
action  action  action  action  Executes a , then b , then … 

Simulation properties  
time 
int  The current simulation time, in milliseconds.  
(won p) 
bool  int  true if player p has won. 

(lost p) 
true if player p has lost. 

(auto x) 
float  int  The current value of the automated input x , in the range [−1, 1].
x has the range [1, 16]. 

(axis x) 
float  int  The current value of the input axis x , in the range [−1, 1]. x
has the range [1, 6]. 

(button x) 
bool  int  The current value of the input button x . x has the range [1,
16]. 

Item IDs  
(node x) 
node  int  The item with ID x . Item IDs are only distinct within that item type,
so two items of different types can have the same ID (e.g. (link 0) and (ball
0) ). 

(link x) 
link  
(ball x) 
ball  
(sheet x) 
sheet  
(weldjoint x) 
weldjoint  
(gearedjoint x) 
gearedjoint  
(differentialjoint x) 
differentialjoint  
(curve x) 
curve  
(target x) 
target  
(motor x) 
motor  
(material x) 
material  
(id x) 
int  node link ball sheet weldjoint gearedjoint differentialjoint curve target motor material 
x 's ID. 

Item properties  
(player x) 
int  node link ball sheet object weldjoint gearedjoint differentialjoint motor 
x 's player. 

(material x) 
material  link ball sheet object curve 
x 's material. 

(radius x) 
float  link ball sheet object curve target 
x 's radius (m). 

(mass x) 
float  node link ball sheet object 
x 's mass (kg). 

(anchored x) 
bool  node link ball sheet object 
true if x is anchored. 

(broken x) 
bool  link ball sheet object 
true if x is broken. 

(position x) 
point  node link ball sheet object target 
x 's position (m). 

(velocity x) 
point  node link ball sheet object 
x 's velocity (m/s). 

(moid x) 
float  link  x 's moment of inertia around its direction axis (kg·m²). 

(moip x) 
float  x 's moment of inertia around an axis perpendicular to its direction
(kg·m²). 

(length x) 
float  x 's length (m). 

(direction x) 
point  x 's direction (unitlength). 

(expansion x) 
float  x 's expansion (controlled by its length motors), in the range [−1, 1].
Positive for expansion, negative for contraction. 

(rotationvelocity x) 
float  x 's rotation velocity (rad/s). 

(rotationreactionvelocity x) 
float  x 's rotation reaction velocity (rad/s). 

(isaxle x) 
bool  ball  true if x has an axle joint. 

(isaxlehub x) 
bool  true if x has an axle hub joint. 

(isaxlefixed x) 
bool  true if x has an axle fixed joint. 

(moi x) 
float  x 's moment of inertia (kg·m²). 

(normal x) 
point  sheet  x 's normal (unitlength). 

(isangle x) 
bool  weldjoint gearedjoint differentialjoint 
true if x is an angle joint. 

(ishub x) 
bool  weldjoint  true if x is a hub joint. 

(isfixed x) 
true if x is a fixed joint. 

(isrotationmotorreactionhub x) 
true if x is a rotation motor reaction hub joint. 

(isrotationmotorreactionfixed x) 
true if x is a rotation motor reaction fixed joint. 

(iscylinder x) 
bool  curve  true if x is a cylinder curve. 

(istorus x) 
true if x is a torus curve. 

(isflat x) 
true if x is a flat curve. 

(startposition x) 
point  target  x 's start position (m). 

(startradius x) 
float  x 's start radius (m). 

(islength x) 
bool  motor  true if x is a length motor. 

(isrotation x) 
true if x is a rotation motor. 

(isthrust x) 
true if x is a thrust motor. 

Item accessors  
(connectedball x) 
ball  node  x 's connected ball. 

(node1 x) 
node  link sheet 
x 's first node. 

(node2 x) 
x 's second node. 

(node3 x) 
node  sheet  x 's third node. 

(centrenode x) 
node  ball  x 's centre node. 

(axlelink x) 
link  ball  x 's axle link. 

(link1 x) 
link  sheet weldjoint gearedjoint differentialjoint 
x 's first link. 

(link2 x) 
x 's second link. 

(link3 x) 
link  sheet differentialjoint 
x 's third link. 

Item tests  
(inside x y) 
bool  link ball sheet object 
target  true if x is completely inside y . 

(partlyinside x y) 
true if x is partly inside y . 

Contacts  
(1player x) 
int  contact  x 's first/second item's player. 

(2player x) 

(1anchored x) 
bool  contact  true if x 's first/second item is anchored. 

(2anchored x) 

(1islink x) 
bool  contact  true if x 's first/second item is a link. 

(2islink x) 

(1isball x) 
bool  contact  true if x 's first/second item is a ball. 

(2isball x) 

(1issheet x) 
bool  contact  true if x 's first/second item is a sheet. 

(2issheet x) 

(1isobject x) 
bool  contact  true if x 's first/second item is an object. 

(2isobject x) 

(1iscurve x) 
bool  contact  true if x 's first/second item is a curve. 

(2iscurve x) 

(1isworld x) 
bool  contact  true if x 's first/second item is a world boundary. 

(2isworld x) 

(1link x) 
link  contact  x 's first/second item. 

(2link x) 

(1ball x) 
ball  contact  
(2ball x) 

(1sheet x) 
sheet  contact  
(2sheet x) 

(1object x) 
object  contact  
(2object x) 

(1curve x) 
curve  contact  
(2curve x) 

(1world x) 
int  contact  x 's first/second item. World boundaries have the range [0, 5],
corresponding to the left/right/bottom/top/back/front of the world space. 

(2world x) 

(overlap x) 
float  contact  The overlap between x 's items (m). 

(velocityn x) 
float  contact  The velocity between x 's items along the contact normal direction (m/s). Positive
if the items are moving towards each other, negative if they are moving away from each other. 

(velocityp x) 
float  contact  The velocity between x 's items along the contact perpendicular direction (m/s).
Always positive. 

(effectivemass x) 
float  contact  The effective mass between x 's items (kg).m_{1} m_{2} ÷ (m_{1} +
m_{2} ) 

Build requirement definitions  
(require v x) 
none  unassigned  bool  Defines the build requirement that x must evaluate to true for
v ∈ [0, numplayers ). 

Display definitions  
(display v) 
none  boolvariable intvariable floatvariable pointvariable 
Displays the variable v on the play screen. 

(playerdisplay v) 
Displays the variable v on the play screen for each player. If v is
an array variable then the index is offset by the player index. So (playerdisplay (v
0)) would use (v 0) for the first player, (v 1) for the second
player, (v 2) for the third player, and so on. 

(editdisplay v) 
Displays the variable v on the edit screen. 

(display v x) 
none  floatvariable pointvariable 
int  As above, but with v displayed to x decimal places. 

(playerdisplay v x) 

(editdisplay v x) 

(displaytime v) 
none  intvariable  As above, but with v interpreted as a time in milliseconds and
displayed as [hh:]mm:ss.sss . 

(playerdisplaytime v) 

(editdisplaytime v) 

(displaybar v) 
none  floatvariable  As above, but with v displayed as a bar. Bars can display values of
v in the range [0, 1]. 

(playerdisplaybar v) 

(editdisplaybar v) 

silentwon 
none  Supresses the win notification. Used to make "tea break" bonus levels that are won by just watching. 
Toplevel expressions must be either a varible declaration, an action, a build requirement definition, or a display definition.
The input rules are not allowed to use the setwon
, setlost
,
setbroken
, setposition
, setradius
,
setgravity
, setairdensity
, require
,
playerdisplay
, playerdisplaytime
, playerdisplaybar
, or
silentwon
expressions.
Singleline comments start with a #
or @
character and continue to the
end of the line. Multiline comments are enclosed between {}
characters, and can be
nested. The @
comments are used as a description of the following rule – shown
in the level preview and in place of the rule code when a build requirement has not been met.
These rules define something like a sumo competition, where players start off inside a target and try to push each other out. The last player remaining inside wins.
@Your creation mass must be under 100 kilograms.
(require
p
(<=
(sum
(playerobjects p)
o
true
(mass o)
)
100.0
))
@You lose if any part of your creation goes outside the target, or it gets completely broken.
(for
(interval 0 numplayers)
p
(if
(!
(all+
(playerobjects p)
o
(! (broken o))
(inside o (target 0))
))
(setlost p)
))
@The last player remaining wins.
(for
(interval 0 numplayers)
p
(if
(&
(! (lost p))
(all
(interval 0 numplayers)
p2
(
(= p2 p)
(lost p2)
)))
(setwon p 1)
))