| Method | Description |
|---|---|
getState() | Gets the signal state |
isForcedRed() | Checks if the red signal is locked |
setForcedRed(forced) | Locks/Unlocks the red signal |
getSignalType() | Gets the signal type |
cycleSignalType() | Switches the signal type |
listBlockingTrainNames() | Lists trains triggering the signal |
| Event | Description |
|---|---|
train_signal_state_change | Triggers whenever the signal changes |
getState()
Gets the train signal's currently displayed signal, as how the trains see it.
Returns
stringThe color of the signal currently displayed - either "RED", "GREEN" or "YELLOW" (Only on CROSS_SIGNAL types).
isForcedRed()
Checks if the signal is forced red by the computer.
Returns
booleanThe state of the computer-controlled red light.
setForcedRed(forced)
Forces the signal to be red regardless of redstone and free space ahead.
Goes back to default behaviour when losing connection with the computer.
Parameters
- forced:
booleanenable/disable forced red mode.
getSignalType()
Gets the train signal's signal type (Normally toggled with a wrench) as how the trains see it.
Returns
stringThe signal type - either "ENTRY_SIGNAL" or "CROSS_SIGNAL".
cycleSignalType()
Cycles through the train signal's signal types like if you used a wrench on it.
listBlockingTrainNames()
Retrurns
tableList of train namestrings occupying the track.
Events
The following are events that can be accessed with os.pullEvent(filter).
Event: train_signal_state_change
Triggers whenever the signal changes.
Returns
stringPosition of the signal that triggered this event, relative to the computer.stringName of the signal it switched to, either "RED", "GREEN" or "YELLOW" (Only on CROSS_SIGNAL types).
Example
Print what signal has changed to what state in the terminal.
lua
while true do
local event, side, status = os.pullEvent("train_signal_state_change")
print("Signal on side", side, "changed to", status)
end