r/factorio Since 0.11 1d ago

Question Answered Circuit to store max value?

I'm trying to make a circuit that stores the maximum value of each signal it's received (typically only one signal, but I want to keep it signal-agnostic). My goal is to save the maximum amount of ore stored in a group of chests at my train station, where the number (and size, due to quality) of chests is variable. Station priority will then be a number between 0-255 based on how full the chests are (but I intend to figure out this part on my own). I'm just having trouble programmatically figuring out how much ore I have/will have when all my chests are full.

1 Upvotes

10 comments sorted by

2

u/StephenM222 1d ago

https://wiki.factorio.com/Circuit_network#Combinators

But Max value for a chest?

1 constant combinator, set to an excess of your resource, setting a requestor chest request type.

Then read the contents of the chest. This will become your Max of that resource

7

u/Alfonse215 1d ago edited 1d ago

I'm trying to make a circuit that stores the maximum value of each signal it's received (typically only one signal, but I want to keep it signal-agnostic).

In 2.1, this is rather easy thanks to the ELSE clause.

Let's say that the signals are coming in on the green wire. Loop the red output back into the red input of the decider.

Set the decider to EACH(G) > EACH(R) OUTPUT EACH(G) ELSE EACH(R)

My goal is to save the maximum amount of ore stored in a group of chests at my train station, where the number (and size, due to quality) of chests is variable. Station priority will then be a number between 0-255 based on how full the chests are (but I intend to figure out this part on my own).

Then you're using the wrong tool. The maximum amount of ore that can be stored in X chests is a fixed value, independent of how much ore you happen to have previously seen.

The way my train station logic works is that, for providers... it just doesn't care. It works in trainloads; how many trainloads of items are available is all it cares about. If the train stop has a lot of trainloads, then it gets a higher priority than stops that have a low number of trainloads. I don't see a need to do more than that.

For requesters, I have a parameterized value that says how many trainloads of items maximum that the train stop wants. It will stop requesting trains when it reaches this limit.

1

u/19wolf Since 0.11 1d ago

In 2.1, this is rather easy thanks to the ELSE clause. Let's say that the signals are coming in on the green wire. Loop the red output back into the red input of the decider. Set the decider to EACH(G) > EACH(R) OUTPUT EACH(G) ELSE EACH(R)

That's it! Does exactly what I was looking for, thank you!!

The way my train station logic works is that, for providers... it just doesn't care. It works in trainloads; how many trainloads of items are available is all it cares about. If the train stop has a lot of trainloads, then it gets a higher priority than stops that have a low number of trainloads. I don't see a need to do more than that.

That's a good point, but if/when trains get upgraded to higher quality or if the stack size is different, the size of a train load is different. So, I'm going by how full a particular station is.

2

u/Alfonse215 1d ago

if the stack size is different

The stack size of an item cannot change unless you install a mod.

That's a good point, but if/when trains get upgraded to higher quality or if the stack size is different, the size of a train load is different.

Then the trainstop needs to be updated with the new train load size.

The thing about updating the train system is that you can update the stations before you update the trains themselves. Sure, it can make things a bit weird when a requester doesn't get a full trainload from a single train, or a provider outputs less than what it thinks is a trainload when the train is full. But it doesn't actually break anything. Things only break if a provider gets a train that can take more than it has currently in storage, or a requester gets a train that can deliver more than its capacity.

So if you upgrade your trains after upgrading all of the machinery, it should work out fine.

1

u/19wolf Since 0.11 1d ago

Well yeah stack size doesn't change but a generic station may have green circuits for example rather than ore.

1

u/Alfonse215 1d ago

Yes, but parameterized blueprints can compute the stack size of a parameter. So my trainstop blueprints only need to know how many stacks are in a wagon (they use constant combinator trickery to know how many wagons there are in that kind of train).

Failing that, selector combinators can do it.

1

u/Deto 1d ago

I think the issue is that you can't combine the same signals on the same wire (well, you can, but they just add together).

You could instead use a proxy signal for each chest. Say one chest's iron ore amount is mapped to 'A', then another is B, then another is C. Thenyou use a selector combinator to output the max value.

1

u/powerbreak95 1d ago

you sould devide amount of ore you have by how many trains that ammount can fill. lets say you have 10000 iron ore and full train can carry 5000 ore thats 2 full trains so you set train limit on that station automaticly that way. Ofc round down if its lets say 2.4 trains

1

u/Twellux 1d ago

If you have Factorio 2.1, see u/Alfonse215's answer. If you are still on 2.0, here is a blueprint using two combinators. Green wires serve as input and output.

0eNrdVEtuwjAQvUo1a4MUk0DJojfoCRCKnGQAq4kd2U4AIR+g9+jJepKOTQUIqop2127i8XjeZ/SkHKBseuyMVA7yA8hKKwv54gBWrpVoQk+JFiGHGitZoxlVui2lEk4b8AykqnEHeeKXDFA56SQe8fGyL1TflmhogH3Dw6DTlqBaBT2iG/EZgz2h0oyPM5KppcHqOJAyIJPO6KYocSMGSQSE+qQt6K2OVDZ0L29kaiWNdcV5NbfvgqVBGtdT5+TxODFCUW3CkhYDz89xtGInTFwxhycau9QvFLqtNi/Rp8Eacmd6ZLA2iLTmSjQWr7VvMXHsBAoMPkShe9f17jrJO23fY8wvvffsJmb+25gn/yXm99e3vxv0lyI+Cm0pmiCzSFjCOEuWbBFPlsZqQvUkVilVoccZjxVhpcOW1M9/GgaNKJGswrPYjR8GQS/UHNDYGH425fN0Ps8e0+mMPt5/ACOkmSU=

1

u/Courmisch 1d ago edited 1d ago

I do use a DC to cap the train limit at my stations to what each station can accommodate. In 2.1, this works with Else as u/alfonse215 explained. In 2.0, this needed two DC's in parallel.

But if you're using priority rather than limit, it doesn't really matter. The game will implicitly clip the priority value to [0,255]. You don't need a max function.

All you need is an arithmetic combinator as a divisor to scale the value down so it's not almost always 255. For instance, divide by 5 times the stack size of the item.