-
Notifications
You must be signed in to change notification settings - Fork 17
SL Controller Commands
Beside internal functions see SaferLua the controller supports the following commands to control and monitor other nodes:
-
$print(text, text, text)
- Output a text string on the 'outp' tab of the controller menu. The function accepts up to three text arguments. E.g.:$print("Hello ", name, " !")
-
$loopcycle(seconds)
- This function allows to change the call frequency of the controllers loop() function, witch is per default one second. For more info, see Loops and Events. -
$events(bool)
- Enable/disable event handling. For more info, see Loops and Events. -
$get_ms_time()
- Returns time with millisecond precision. -
$time_as_str()
- Read the time of day (ingame) als text string in 24h format, like "18:45". -
$time_as_num()
- Read the time of day (ingame) als integer number in 24h format, like 1845. -
$get_input(num)
- Read one input value provided by an external node with the given number num. The node has to be configured with the number of the controller to be able to send status messages (on/off commands) to the controller. num is the number of the remote node, like "1234".- a Player Detector with number "0001" is configured to send on/off commands to a node with number "0002".
- The SaferLua Controller with number "0002" will receive these commands as input messages.
- The program on the SaferLua Controller can always read the last input message from node with number "0001" by means of:
sts = $get_input("0001")
-
$get_status(num)
- Read the status from an external node with the given number num. Standard nodes return a status string like: 'running', 'stopped', 'blocked', 'standby', 'fault', or "defect". See nodes for further information to other tubelib compatible nodes, like Pushers, Harvester, Quarry. -
$get_player_action(num)
- Read the player action status from a Tubelib compatible chest with the given number num. The function returns tree values: player-name, action, item-name. -
$get_counter(num)
- Read the item counter of a Pusher/Distributor node with the given number num. The counter is incremented with each pushed item. The Pusher returns the value as number, the Distributor returns a table with a number for each slot, like:{red=1, green=0, blue=8, yellow=0}
An example is here available. -
$clear_counter(num)
- Set the counter(s) from Pusher/Distributor to zero. An example is here available. -
$get_fuel_status(num)
- Read the fuel status from a fuel consuming node like Harvester and Quarry. The node returns "full" or "empty". num is the number of the remote node, like "1234". -
$playerdetector(num)
- Read the name status from a Player Detector with the number num. If no player is nearby, the nodes returns an empty string""
. -
$send_cmnd(num, text)
- Send a command to another node. num is the number of the remote node, like "1234". text is the command string like "on". See [nodes]] for supported node commands. -
set_filter(num, slot, val)
- Enable/disable a Distributor filter slot. num is the number of the Distributor node. slot is a color and is used to select one of the Distributor sides: "red", "green", "blue", and "yellow". val is either "on" (enable filter) or "off" (disable filter). -
$display(num, row, text,...)
Send a text string to the display with number num. row is the display row, a value from 1 to 9. text is the string to be displayed. This function allows up to 3 text strings. -
$clear_screen(num)
Clear the screen of the display with number num. -
$position(num)
Returns the position '(x,y,z)' of the device with the given num.
The Server is used to store data permanently/non-volatile. It can also be used to share data between several Controllers.
-
$server_write(num, key, value)
- Store a value on the server under the key key. key must be a string. value can be either a number, string, boolean, nil or data structure. But this command does not allow nested data structures. num is the number of the Server, like "1234". Example:$server_write("0123", "state", state)
-
$server_read(num, key)
- Read a value from the server. key must be a string. num is the number of the Server, like "1234".
The Terminal can send text strings as events to the Controller. In contrast the Controller can send text strings to the terminal.
-
$get_term()
- Read a text command received from the Terminal -
$put_term(num, text)
- Send a text string to the Terminal. num is the number of the Terminal.
Messages are used to transport data between Controllers. Messages are text strings or any other data plus the sender number. Incoming messages are stored in a message queue (up to 10) and can be read one after the other.
-
$get_msg()
- Read a received message. The function returns the sender number and the message. -
$send_msg(num, msg)
- Send a message to another Controller. num is the destination number.
-
$chat(text,...)
- Send yourself a chat message. This function allows up to 3 text strings. -
$door(pos, text)
- Open/Close a door at position "pos".
Example:$door("123,7,-1200", "close")
.
Hint: Use the Tubelib Programmer to easily determine the door position.
All available commands to control other nodes are also documented in game (controller menu).