Computers and Connections

All active blocks in the game have either input ports, output ports or both. These pass values from -1 to +1, and can be connected to each other by wireless network connections.

Apart from the sensors and motors, which are described elsewhere, there are Computer blocks which can run player-originated code. Each Computer is completely self-contained and cannot communicate with anything else in the game except through its input and output ports – there are no global variables in the code and no programming API at all to consider. It is up to you to define and document the rules by which certain Computer blocks are meant to be attached to sensors and motors.

The code running on each Computer is executed once, when the player loads a pre-existing program or finishes editing a program. After that, there are event handlers that are run if defined. Currently, only the tick() function is run if defined, without arguments, once per physics tick (100 times per second).

The programming language used is Lua, but with most standard library functions disabled except the basic programming constructs, mathematics and string functions.

The input ports are available in the array inputs[], with indexes 1 to 16, and output port values are taken from the array outputs[] (same index range). Global variables inside each Computer keep their value between event handler invocations but are reset when the Computer itself is reset (after loading a new program or changing the running program). Please note that global variables are also currently reset after a save and load of the world (this will be fixed in a coming release). Due to these resets of global variables it is good practice to make sure the construction handles random restarts no matter which state the motors and actuators are in.

When placing a computer block in the world, a pop-up will ask you if you want to create a completely new piece of code or re-use or clone an existing code. Currently you cannot explicitly name new codes, so you need to remember the auto-generated names – this is on the TODO-list.