Adding RailSignal.changeState
Adding RailSignal.changeState
Useful for creating custom rail signals which depend on things like the state of trains.
Last edited by BronzW on Sat Jun 25, 2022 4:23 pm, edited 2 times in total.
Re: Adding RailSignal.getTrainsInBlock and RailSignal.changeRailSignalState
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).
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
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?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).
Last edited by BronzW on Fri Jun 24, 2022 8:54 am, edited 1 time in total.
Re: Adding RailSignal.getTrainsInBlock and RailSignal.changeRailSignalState
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:
If you want to get ahold of me I'm almost always on Discord.