Adding RailSignal.changeState

Things that we aren't going to implement
BronzW
Manual Inserter
Manual Inserter
Posts: 4
Joined: Thu Jun 23, 2022 6:47 pm
Contact:

Adding RailSignal.changeState

Post by BronzW »

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.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2972
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Adding RailSignal.getTrainsInBlock and RailSignal.changeRailSignalState

Post 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).
BronzW
Manual Inserter
Manual Inserter
Posts: 4
Joined: Thu Jun 23, 2022 6:47 pm
Contact:

Re: Adding RailSignal.getTrainsInBlock and RailSignal.changeRailSignalState

Post 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?
Last edited by BronzW on Fri Jun 24, 2022 8:54 am, edited 1 time in total.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14250
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Adding RailSignal.getTrainsInBlock and RailSignal.changeRailSignalState

Post 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 1380 times
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Won't implement”