Skip to content
Bas edited this page Jan 12, 2024 · 3 revisions

Getting started

Make sure to get the api.lua file in your project directory first

Example code:

local api = require("api") --Call the api
api.connect(port,id[optional]) --Make a connection to the server specified on the port.
api.horn(1) --Simple example. Makes train 1 horn.

Arguments

locomotive

api.connect(port, ID[optional])

Makes a connection to a server. If no ID is specified, it broadcasts on that port to get the modem server ID. This will be saved for further use, so this is the first function you are required to call before using the API.


api.getAllLocs()

Returns all locomotives that the server currently has. Returns an array.


api.info(id)

Returns an array of information of the locomotive with his ID.


api.consist(id)


api.getTag(id)

Returns the tag of the locomotive as a string.


api.setTag(id, tag)

Set the tag of the locomotive, which can be retrieved with api.getTag()


api.setThrottle(id, value)

Set the throttle of the locomotive. Accepts a value between 0 and 1


api.setReverser(id, value)

Set the reverser of the locomotive. Accepts a value between -1 and 1


api.getPos(id)

Returns the position of the locomotive. In x, y, z format


api.setBrake(id, value)

Set the brake of the locomotive. Accepts a value between 0 and 1.


api.setTrainBrake(id, value)

Set the Train brake of the locomotive. Accepts a value between 0 and 1.


api.setIndependentBrake(id, value)

Set the Indepent brake of the entire train. Accepts a value between 0 and 1.


api.horn(id)

Horn the locomotive


api.bell(id, value)

Turn the bell on or off. Accepts a 0 or 1.


api.getLinkUUID(id)

Returns the UUID of the locomotive.


api.getIgnition(id)

Returns the ignition. Is true or false


api.setIgnition(id, value)

Turn the ignition on or off. Requires true or false


Redstone

api.setRedstone(id, value)

Set the Redstone output. Value can be between 0 and 15.