Page 1 of 1

Adding RailSignal.changeState

Posted: Thu Jun 23, 2022 7:06 pm
by BronzW
Useful for creating custom rail signals which depend on things like the state of trains.

Re: Adding RailSignal.getTrainsInBlock and RailSignal.changeRailSignalState

Posted: Thu Jun 23, 2022 9:49 pm
by boskid
Unfortunately no.

There is no easy way to control the state of signals from Lua in a way to make it possible to implement new custom signals. Rail signals (both normal and chain) can be seen as 2 separate functions which for many may not be obvious they are separate. First there is the signal part where a train trying to pass a signal checks if it is able to reserve given signal or if it cannot. Everything related to trains movement is based on being able to reserve a signal. Signal reservation updates are immediate so if within a single tick a signal is released and then acquired, everything works fine. Then there is completly separate feature of signals which is their colors which trains completly do not care about - those are either deduced directly from state of reservations (normal signals) or updated once per tick if state of some signals recently changed (chain signals). I have no idea what exact part of the signal state you want to change, if its color then it is mostly a pointless change, and if you want to change reservations, that is a really hard topic because they have to be responsive (and not updated once per tick).

Re: Adding RailSignal.getTrainsInBlock and RailSignal.changeRailSignalState

Posted: Thu Jun 23, 2022 10:14 pm
by BronzW
boskid wrote:
Thu Jun 23, 2022 9:49 pm
Unfortunately no.

There is no easy way to control the state of signals from Lua in a way to make it possible to implement new custom signals. Rail signals (both normal and chain) can be seen as 2 separate functions which for many may not be obvious they are separate. First there is the signal part where a train trying to pass a signal checks if it is able to reserve given signal or if it cannot. Everything related to trains movement is based on being able to reserve a signal. Signal reservation updates are immediate so if within a single tick a signal is released and then acquired, everything works fine. Then there is completly separate feature of signals which is their colors which trains completly do not care about - those are either deduced directly from state of reservations (normal signals) or updated once per tick if state of some signals recently changed (chain signals). I have no idea what exact part of the signal state you want to change, if its color then it is mostly a pointless change, and if you want to change reservations, that is a really hard topic because they have to be responsive (and not updated once per tick).
What makes the mod different from using circuits to change the rail signal? Would it be possible to somehow emulate a circuit connection in a mod script somehow?

Re: Adding RailSignal.getTrainsInBlock and RailSignal.changeRailSignalState

Posted: Thu Jun 23, 2022 11:44 pm
by Rseding91
Circuits can only 'request to close' a signal; they can never force it to be green and even in the 'try to make it closed' state the tooltip explains that it's not a guarantee that it will happen:
Untitled.png
Untitled.png (69.6 KiB) Viewed 1229 times