Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
blazespinnaker
Filter Inserter
Filter Inserter
Posts: 495
Joined: Wed Sep 16, 2020 12:45 pm
Contact:

Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by blazespinnaker »

I'm trying to add a wait condition such that the train doesn't leave the train stop if there is both a signal present and red signal=1 (the signal which comes from a nearby rail signal)

It should leave if the red signal is not present. I also have an and clause of wait 30 seconds.

I've tried using the Everything signal to detect a lack of signal, but that doesn't seem to work. My guess is there is a signal present on the Train which is blocking it from evaluating to true (Train identifier?).

Is this possible? Or do I have to wire up every train stop?
OptimaUPS Mod, pm for info.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1095
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by Pi-C »

blazespinnaker wrote:
Wed Oct 06, 2021 5:01 am
It should leave if the red signal is not present. I also have an and clause of wait 30 seconds.
Put a normal signal after a train stop and connect the signal with red or green wire to the train stop, like this:
train_signal.png
train_signal.png (933.2 KiB) Viewed 298 times
By the way, I think it would be better to negate the condition: Don't make the train leave if the signal IS NOT RED, but on IS GREEN:
train_signal_reverse.png
train_signal_reverse.png (35.39 KiB) Viewed 298 times
Of course, you can also use combinators to set the signal:
close_signal.png
close_signal.png (274.39 KiB) Viewed 298 times
If the constant combinator is turned off, the signal will be green and the condition in the train schedule will be true.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

blazespinnaker
Filter Inserter
Filter Inserter
Posts: 495
Joined: Wed Sep 16, 2020 12:45 pm
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by blazespinnaker »

may be missing something here. Circuits tend to make my head hurt because ops I assume as always present (such as variable existence checks) don't seem to be present.

Rather than trying to re-explain or try to poke holes in your explanation, let me start by just asking a simple question - if the stop is not wired up at all (no combinators, signals, or wires connected to the train stop), will it still proceed after 30 seconds?

Eg, here is the condition (note time fully expired):
expire.png
expire.png (10.02 KiB) Viewed 253 times
And here is the stopped train:
train.png
train.png (190.63 KiB) Viewed 250 times
Only by deleting the circuit condition in the train route, will the train proceed.

Obviously, the condition won't work as no green signal is present. But that's the crux of the problem. I have many train stops all with the same name but only one of those stops I particularly want to signal. I'm wondering if I have to wire them all up or if there is some default behavior I can rely on.

As mentioned above, I tried the Everything virtual signal, but it didn't help.
OptimaUPS Mod, pm for info.

blazespinnaker
Filter Inserter
Filter Inserter
Posts: 495
Joined: Wed Sep 16, 2020 12:45 pm
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by blazespinnaker »

If it's not possible, I will probably resort to a hack using one of the other conditions such as cargo count. I'll remove the cargo item once the rail signal light changes to green.
OptimaUPS Mod, pm for info.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1095
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by Pi-C »

blazespinnaker wrote:
Wed Oct 06, 2021 1:44 pm
Rather than trying to re-explain or try to poke holes in your explanation, let me start by just asking a simple question - if the stop is not wired up at all (no combinators, signals, or wires connected to the train stop), will it still proceed after 30 seconds?
Yes, you must hook up the signal to the train stop! It's even in the name: "Circuit condition". If you want to check something on the circuit network, you must feed something into it.

One thing you should be aware of: In Lua, "x = 0" and "x = nil" are two different things. In the first case, you set x to the number 0, in the second case, you remove x altogether. With combinators, any signal that is not on the wire will default to a value of 0. So if you set the condition to "RED == 0", it will always be true if the signal is not connected, as well as if the signal is connected but green.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

blazespinnaker
Filter Inserter
Filter Inserter
Posts: 495
Joined: Wed Sep 16, 2020 12:45 pm
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by blazespinnaker »

Yeah, but that's exactly what I don't want to do :)

And I believe the everything virtual signal is exactly for this use case. However, it doesn't work with trains as there are semi-hidden signals present.

For some reason, likely performance, wube didn't add an op which checks for a specific signal presence.
OptimaUPS Mod, pm for info.

torne
Filter Inserter
Filter Inserter
Posts: 331
Joined: Sun Jan 01, 2017 11:54 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by torne »

!= 0 is the condition for "signal present". The signal being present and having a nonzero value are the same thing in Factorio circuit logic.

If you want to be able to inhibit a train from leaving a stop until it gets a signal but have the train be allowed to leave if the station isn't hooked up to a circuit network then just make the condition "red = 0" and send a red signal of 1 if you want the train to stick around.l (i.e. invert your input signal). Stops with no wire connected will not prevent the train from leaving because if no wire is connected the red signal will be zero.

quyxkh
Filter Inserter
Filter Inserter
Posts: 914
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by quyxkh »

blazespinnaker wrote:
Wed Oct 06, 2021 5:01 am
[wait if] there is both a signal present and red signal=1 (the signal which comes from a nearby rail signal)

It should leave if the red signal is not present. I also have an and clause of wait 30 seconds.
What is this other signal? If the red signal's 1 there's a signal present. Depart on red=0 and timer expired seems to match that part of your description, but that "both" hints at something else.

You can add a further set of conditions, timer expired and red = 0 or timer expired and iron-ore = 0 if it's that specific other signal. If you mean *any* other signal, i.e. wait if red = 1 and anything else also nonzero, that will take wiring, if these other signals won't ever be negative just each * red ⇒ red and your departure condition is red < 2; for howitzer-proof you need an each != 0 ⇒ 1 each so things don't cancel out.

blazespinnaker
Filter Inserter
Filter Inserter
Posts: 495
Joined: Wed Sep 16, 2020 12:45 pm
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by blazespinnaker »

Interesting, I admit I didn't try that outside of train context as it wasn't relevant to my problem here. I did try that with trains (and many other combinations).

Anyways, that doesn't work. Eg:
train.png
train.png (190.63 KiB) Viewed 209 times
Train still doesn't move until I delete the circuit condition. (Again, no wires connected to Train stop)
OptimaUPS Mod, pm for info.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1095
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by Pi-C »

blazespinnaker wrote:
Wed Oct 06, 2021 4:47 pm
Train still doesn't move until I delete the circuit condition. (Again, no wires connected to Train stop)
Interesting. Seems I have to revise my earlier statement:
Pi-C wrote:
Wed Oct 06, 2021 3:35 pm
So if you set the condition to "RED == 0", it will always be true if the signal is not connected, as well as if the signal is connected but green.
Apparently, circuit connections will only be evaluated if the trainstop is connected to something -- a signal, a combinator, or any other entity with a connector -- on the circuit network.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

torne
Filter Inserter
Filter Inserter
Posts: 331
Joined: Sun Jan 01, 2017 11:54 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by torne »

blazespinnaker wrote:
Wed Oct 06, 2021 4:47 pm
Interesting, I admit I didn't try that outside of train context as it wasn't relevant to my problem here. I did try that with trains (and many other combinations).

Anyways, that doesn't work. Eg:

train.png

Train still doesn't move until I delete the circuit condition. (Again, no wires connected to Train stop)
Ah. For all other entities it's only possible to set circuit conditions in the UI if there's a circuit wire connected (as the UI doesn't appear otherwise), and if the wire is disconnected the condition is ignored (though still retained if you reconnect a wire). For train schedules the UI isn't directly associated with a particular train stop entity so it doesn't have any way to know whether the stop will have a wire or not.. and I guess this is the result? You might want to report that as a bug but I'm not sure what the behaviour really *should* be.

In any case if that doesn't work then I think you can safely assume that what you want is not currently possible; there's no alternative way to do this that might work. Does it work if you just connect a wire between the stop and a random electric pole with no other circuit components connected, and enable "send to train" in the train stop options? If so then that might be the easiest workaround; just make sure you have a wire connection in your blueprints even if it's to nothing, and then use signal=0 as the condition as I suggested.

blazespinnaker
Filter Inserter
Filter Inserter
Posts: 495
Joined: Wed Sep 16, 2020 12:45 pm
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by blazespinnaker »

Hard to search on bugs for train circuit conditions signals. :p

I just went and wired up all the stops, one time pain. TG you can paste in wires.

Probably quite an edge case
OptimaUPS Mod, pm for info.

quyxkh
Filter Inserter
Filter Inserter
Posts: 914
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by quyxkh »

Pi-C wrote:
Wed Oct 06, 2021 5:35 pm
Apparently, circuit connections will only be evaluated if the trainstop is connected to something -- a signal, a combinator, or any other entity with a connector -- on the circuit network.
Otherwise, how would the train stop know which signals to check?

astroshak
Filter Inserter
Filter Inserter
Posts: 478
Joined: Thu May 10, 2018 9:59 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by astroshak »

As far as I know, a 0 signal is the same in Factorio as a “null” signal. That is, if there is a CC that has Red = 1 and you have something else that outputs to that wire a Red = -1, then the two would cancel out and there would no longer be any Red signal. Its not a case of Red = 0, as that implies there is a Red signal that has a value of 0.

Instead of telling the train to “Wait when the Red signal is 1”, tell it to “Wait until Red < 0”.

Have that Rail Signal output its signal to the Train Stop. It will set Red to 1, or leave Red alone, depending on what color the Rail Signal is. Also wire to the Train Stop a Constant Combinator, outputting Red = -1.

If the Rail Signal is Red, it outputs Red = 1 and that gets added to the -1 from the CC, removing Red as a signal on the wire. Red is no longer less than zero, so the train would wait.
If the Rail Signal is anything other than Red, it does not add Red = 1 to the circuit, so the CC value of Red = -1 stands, and the train can happily move on.

I’ll do something similar when making a Building Train style setup. CC outputs the negative amount of the minimum material I want on hand (-8 Nuclear Reactors, -350 Heat Pipe, etc. - what exactly depends on the Building Train). That then gets wired to the output chests at the station, and whatever is in those will build up and render positive the item signals (or straight up zero them out). Train Station is Enabled when Anything < 0. This used to be that trains were generally set up prior to the addition of Train Stop Limits. I still use this for building trains, where there is only exactly one train that has that stop on its schedule and its an “on demand” type of schedule where the train only has to visit any one station only occasionally.

mrvn
Smart Inserter
Smart Inserter
Posts: 4641
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by mrvn »

Please report that as a bug. A train with condition "red = 0" should leave a stop with no wire connected. A 0 is encoded as signal not present so that should already make the train leave. Further other entities ignore the circuit conditions when no wire is connected. E.g. take a belt with wire and set it to "R = 1". Then remove the wire or cut&paste just the belt. The belt with run again. Connect a wire and the belt stops again. Same with pumps, ...

User avatar
MEOWMI
Fast Inserter
Fast Inserter
Posts: 210
Joined: Wed May 22, 2019 12:21 pm
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by MEOWMI »

Yes, X == 0 is exactly the same as "there is no signal X". I agree it is very confusing that it doesn't evaluate to true if it's not connected to any network. Figuring out how the circuit network at the start is already very difficult due to all the weird rules and exceptions, this is yet another weird exception you have to learn unless they actually decide to change this behavior. The best tip I know of is to connect specifically a power pole to whatever cable's signals you want to inspect, as it will show them all on the pole.

mrvn
Smart Inserter
Smart Inserter
Posts: 4641
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by mrvn »

And another oddity. If you set the train stop to output the train count as C and connect a green wire then the train stop sees the number of trains targeting the station. So you could set the train to leave on C=2, i.e. as soon as a second train targets the station. Then one train leaves when another arrives.

But now connect the red wire too. Now the stop sees double the number, C=2, C=4, C=6, ... Same goes for belts.

But for requester chests I believe you can read the contents and set the requests and not have the chests own contents get added to the requests.

blazespinnaker
Filter Inserter
Filter Inserter
Posts: 495
Joined: Wed Sep 16, 2020 12:45 pm
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by blazespinnaker »

That's actually consistent behavior. It sums the signals in the network and you're sending it in via two separate channels.
OptimaUPS Mod, pm for info.

User avatar
Khagan
Fast Inserter
Fast Inserter
Posts: 108
Joined: Mon Mar 25, 2019 9:40 pm
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by Khagan »

mrvn wrote:
Thu Oct 07, 2021 5:31 pm
But for requester chests I believe you can read the contents and set the requests and not have the chests own contents get added to the requests.
Unfortunately not. Setting requests and reading contents are mutually exclusive options. (Perhaps precisely because the undesirable positive feedback would be unavoidable.)

mrvn
Smart Inserter
Smart Inserter
Posts: 4641
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Circuits with TrainsStops, how to do pause only when red signal is present and = 1

Post by mrvn »

Khagan wrote:
Thu Oct 07, 2021 11:25 pm
mrvn wrote:
Thu Oct 07, 2021 5:31 pm
But for requester chests I believe you can read the contents and set the requests and not have the chests own contents get added to the requests.
Unfortunately not. Setting requests and reading contents are mutually exclusive options. (Perhaps precisely because the undesirable positive feedback would be unavoidable.)
Ahh, ok. Must have been wishful thinking. Then it's at least consistent.

Post Reply

Return to “Gameplay Help”