Skip to content

Reference

nightfury34 edited this page Jun 18, 2025 · 32 revisions

Better Signals - Reference

Here is an overview of all values that Better-Signals provides in params in updateFn = function(params)

signal_state [0/1]

signal_state returns the state of the linked signal and indicates if a train will stop in front of the signal.

  • 0: Signal is red. Trains will stop in front of the signal
  • 1: Signal is green. Trains will pass the signal
if params.signal_state and params.signal_state == 1 then
    -- display green
else
    -- display red
end

signal_speed [0-∞]

signal_speed returns the lowest speed between this and the next following signal. Speed is in km/h

if params.signal_speed and params.signal_speed <= 20 then
    -- display 20km/h
elseif params.signal_speed and params.signal_speed <= 30 then
    -- display 30km/h
elseif ...
end

previous_speed [0-∞]

previous_speed returns the lowest speed between the prior and this signal. Can be used to figure out if there was a speed difference. Speed is in km/h

if params.previous_speed > params.signal_speed then
    -- display slow_down
end

isStation [true/false]

isStation returns if the signal is a stop. (Only available in followingSignal)

if params.following_signal and params.following_signal.isStation then
     -- this signal is the last signal before a station
end

entity [0000-9999]

entity returns the id of the entity the signal is linked to.

animationTimer [0.00000-∞]

animationTimer returns the seconds played in this session and can be used to play Animations. Be aware that signals only get updated up to 5 times a second - therefore smooth animations sadly aren't possible using this system.

if params.animationTimer and (tonumber(string.format("%.1f", params.animationTimer)) % .5 == 0) then
    -- add blinking lamp (all .5 secs)
end

params_override

params_override returns all values defined by waypoints on the path to the next signal. - Users can place waypoints between signals and change the name of the waypoints to pass additional values to the signals. This also works if the waypoints are placed on different branch lines. Therefore, this system can for example be used for switch indicators. All values that follow the pattern of key=value will be passed on to this parameter. Multiple values can be separated using a ,. It is important to explicitly check if the key isn't nil - in order to prevent crashes.

It's also important to note that speed=[number] will automatically change the speed value provided in signal_speed

if params.paramsOverride and params.paramsOverride.track and params.paramsOverride.track == 'a' then
     -- display track A is used
end

NOTE: Be aware that all numeric values will get converted into numbers. So if you want to test for params.paramsOverride.trackNr == 2 make sure to test for the value as a number instad of a string.

following_signal

following_signal returns a table with all the above parameters - but from the perspective of the next signal on the path. Therefore, it can be used to indicate more complex "signal-faces" that take the following signals into account. A following signal can, but doesn't have to, include another following signal. So it's advised to explicitly check for params.following_signal before accessing one of its values.

if params.following_signal and params.following_signal.signal_state and params.following_signal.signal_state == 0 then
     -- display warning - next signal shows stop
end

params

params is a value unique to following_signals. It contains all non signal related parameters in a list. So for example x_offest, y_offset, given the construction has these. Therefore the values passed here are unique to the signaling_pack used by the players. So it's advised to use this value accordingly.

if params.following_signal and params.following_signal.params and params.following_signal.params.special == 1 then
     -- display special preSignal
end

Clone this wiki locally