Tutorial:Luacontrollers

Luacontrollers are digital chips to process digiline and mesecon signals. To use it and code it, place it on the ground then right-click it. There are several types of Luacontrollers, such as Luacontroller, Lua-ATC Rail, Lua-ATC Block, and Lua-ATC environment init script.

The Lua code snippets below (included in syntax highlight HTML blocks) is released under CC0, to allow everyone to use them freely.

Mesecon Luacontrollers
Mesecon Luacontrollers is the pure type of luacontroller. It contains 4 mesecon input and output, and allow digiline connected from the side.

Lua-ATC
Lua-ATC stands for "Lua Automatic Train Control". It provides direct access to control the advtrains system and allows digiline access to interact with the world.

Lua-ATC Block
The Lua-ATC Block is a luacontroller that contains codes that can be called by anyone by punching it.

Lua-ATC Rail
The Lua-ATC Rail is a rail with luacontroller chips inside to toggle and control the train by Lua codes.

Lua-ATC Environment Script
These scripts will run once the server starts. It set up the Lua-ATC environment.

Lua Callbacks
Before this, you should know how to write code in Lua.

and
is the mesecons input table. Each pin (A to D) corresponds to a side of the Luacontroller. is the mesecon output table, that have the same mapping as.
 * Luacontrollers only

The following code can open B when A is not toggled, and close B when A is toggled.

is a function to repeat the code after serval seconds. There are two parameters,  (in second) and.

The following code shows how to make a blinky plant.

This is a fork of, but won't spawn new interrupt tasks if one already exists.
 * Lua-ATC only

Memory
The  table will be saved between luacontroller starts, but others not.

The following code shows how to make mesecon signals cycle though 4 ports.

Digilines
Digiline messages can be proceeded by Luacontrollers. When the controller received a digiline message, it generates an event with the following parameters: You can use  function to send a digiline message. It have two required parameters,  and. This can be used to let two or more controllers "chats".

This example will send "World" if it received "Hello" from channel "a".

Data sharing between Lua-ATC elements
There are two tables,  and , to allow sharing data between Lua-ATC elements in the same environment. can be saved between server restarts, but it cannot contain functions and userdata. have similar usage, but it won't be saved between server restart and it can contain all types of contents.
 * Lua-ATC only