Factorio

Factorio

View Stats:
Liwet Nov 18, 2024 @ 6:26pm
Is there a way to count item stacks rather than the items themselves for combinator purposes?
Mainly to deal with smaller numbers involving ores. I know all the ores stack the same but I might want to move other bulky items around with different stack sizes.
< >
Showing 1-13 of 13 comments
PunCrathod Nov 18, 2024 @ 6:27pm 
There is a combinator that lets you do that. Or just put down a chest that has been limited to one stack and fill it with the items.
malogoss Nov 18, 2024 @ 6:36pm 
Read the items total. Divide that by the output of: a selector combinator, that has the items signal as an input, set to output the stack size of items. Then you should have your answer.

I think it would always get rounded down, so account for that in the result. A great opportunity to calculate modulo if you're fancy and want to detect an incomplete stack.
Liwet Nov 18, 2024 @ 6:57pm 
Originally posted by malogoss:
Read the items total. Divide that by the output of: a selector combinator, that has the items signal as an input, set to output the stack size of items.

Is that it? Just stick it through the new combinator thing and I get a stack total? So 200 iron ore will give the same output as 400 iron plates?
malogoss Nov 18, 2024 @ 7:03pm 
Originally posted by Liwet:
Originally posted by malogoss:
Read the items total. Divide that by the output of: a selector combinator, that has the items signal as an input, set to output the stack size of items.

Is that it? Just stick it through the new combinator thing and I get a stack total? So 200 iron ore will give the same output as 400 iron plates?

No. The new combinator spits out the stack size of items. To get to count number of stacks (the question in your OP), you need a bit of extra math, and that's what I described.

For a 200 iron ore input, the new combinator will spit out 50. For a 2 iron ore input, it'll also spit out 50. 400 iron plates, it'll spit out 100. A billion plates, also 100. The size of a single full stack of those items.
Liwet Nov 18, 2024 @ 8:56pm 
And a related question: is there a way to count chests or maximum stacks in a chest? Some of my train stations have 24 chests and some have 18 which yield different maximum stack sizes.
Nellvan Nov 18, 2024 @ 9:37pm 
Originally posted by Liwet:
And a related question: is there a way to count chests or maximum stacks in a chest? Some of my train stations have 24 chests and some have 18 which yield different maximum stack sizes.
AFAIK, no. You need to calculate and put it into an arithmetic combinator yourself (assuming that's where you want to use it).

What can do for future use though, is to make this setup into a parametrized blueprint and turn that value into a parameter. Then you'll get a popup to confirm or change the value everytime you plop down that blueprint.
Last edited by Nellvan; Nov 18, 2024 @ 9:44pm
malogoss Nov 18, 2024 @ 9:48pm 
The way you keep saying "stack sizes" to talk about "number of stacks" only adds to the confusion. I'm really willing to help but it is making it tough.
Liwet Nov 18, 2024 @ 10:16pm 
I want to create a generic train station blueprint with some added combinators. I want to set a station's priority based on how much of a full train it can fill. I want a station with 10 wagons full of items to have a priority higher than a station with 2-wagons full of items.

The problem I'm trying to solve is that I want the priority number of stations with different amounts of loading/unloading chests to mean the same thing. A 3-wagon station that's half full needs to have the same priority number as a 4-wagon station that's half full despite there being a difference of 7,200 items between the two.

So you've helped me figure out stack sizes but now I'm trying to figure out how to count chests or the slots within a chest (and divide that number by 24).
malogoss Nov 18, 2024 @ 11:42pm 
What I'm reading is, you want a blueprint, (mostly made of combinators, not really rail or inserters, those are already built at the stations), that you'll be able to kind of stamp on top of existing train stations, like an update, to make them smart in regards to their priority level.

That is possible. You can't really count the chests based on signals, unless you know they are full or if you did put 1 landmine (or whatever random item) in each chest when you built the stations to make it possible to count the chests.

But it does not matter, and here's what I'd do.

Pick a station.
Get the items total, by connecting all chests.
Divide that by the stack size of the item, as given by a selector combinator.
Then divide that by the number of chests at the station.
Express the result as a "P" signal, feed that to the train stop, that will set its priority based on it.

That's it. "P" is how many stacks worth you have per chest, on average, in the buffer. The closer the buffer is to its full capacity, the higher the priority.

When you blueprint that, include the combinators and the train stop in that blueprint, don't include the station's name in the blueprint, and don't forget to make the # of chests a parameter. When you'll use that blueprint, you'll have to specify how many chests there are at this station, and the related combinator will use that to make its division.

This works as long as ALL stations use chests that are the same size, so to speak. So only wooden chest, or only iron chest, or all logistics and/or steel chests.
Liwet Nov 19, 2024 @ 1:12am 
Originally posted by malogoss:
...

Then divide that by the number of chests at the station.
...

I'm trying to learn how to count the number of empty chests at a station through the game, through combinators or whatever, rather than trying count it like Sesame Street and enter the total manually every time I have to place a station down.
Nellvan Nov 19, 2024 @ 3:23am 
Originally posted by Liwet:
Originally posted by malogoss:
...

Then divide that by the number of chests at the station.
...

I'm trying to learn how to count the number of empty chests at a station through the game, through combinators or whatever, rather than trying count it like Sesame Street and enter the total manually every time I have to place a station down.
There may be some way, for a proper circuit wizard... But some things may just need to be hard-coded. At least now with parameters it's less hard-coded and easier to re-use or remember wtf this thing was supposed to be doing.
  • Use any resource icon/signal, but always the same
  • Use 16 everywhere you use chest size for calculations
  • Use 18 everywhere you use number of chests
  • When you need the number of slots of the whole storage, provide that with an arithmetic combinator (16 * 18 = some signal) plugged into the input of that particular operation
  • Use blueprint parameters to turn the resource icon and "16" and "18" into parameters, label them accordingly
You now have a BP that basically asks you "Which cargo, which chest size and how many of them?" when you place it. That's probably the easiest way to get one variable BP for this, since you cannnot directly read what you want.

As for priority, this is what I'm using:
  • content of all chests divided by stacksize of the cargo item
  • multiply with 255
  • divide by total number of chest slots
For drop off stations, add on:
  • subtract 255
  • multiply with -1
Sure it's extra steps but it uses the whole range of 0-255 for every station and inverts priority for dropoffs.
Last edited by Nellvan; Nov 19, 2024 @ 3:50am
Nellvan Nov 19, 2024 @ 4:15am 
Well after typing all this, I realized the answer is partly already in there. We can read the stacksize of the item, number of slots of a storage = number of items divided by stacksize.

We just need a way to confirm that the storage is 100% full. I can't check ingame right now, is there a way to read inserter activity? Like, if inserter carries something but is inactive, the chest gotta be full ? Or if belt infront of the inserter has items on it, I think they alwys pick stuff up but not sure.

I still feel like this overcomplicates things so much, just remember the chest sizes or read them in the tooltip and count the amount you're placing ;)
Last edited by Nellvan; Nov 19, 2024 @ 4:15am
malogoss Nov 19, 2024 @ 11:48am 
Originally posted by Liwet:
Originally posted by malogoss:
...

Then divide that by the number of chests at the station.
...

I'm trying to learn how to count the number of empty chests at a station through the game, through combinators or whatever, rather than trying count it like Sesame Street and enter the total manually every time I have to place a station down.

As I said previously. Unless you prepared for that, you can't do it directly.

But if you happen to have dropped a landmine in each chest when building the station just "by accident", then you can do it.

Or be creative. Read what the inserters are holding. Divide that by their max capacity. The result is the number of chests you have, when they are all moving cargo. Store that in a memory cell or something.

If counting 16 chests is too much work for you, that's fine. But it's up to you to make your laziness work. The good news is, this is Factorio. When asking "can it be done?", the answer is almost always yes. If you one day want to be a combinator expert, maybe for now you should count chests. Then take 20 minute or 2 months to think about how you could count chests with logic circuits.

That'll be it for me. Good luck.
Last edited by malogoss; Nov 19, 2024 @ 11:59am
< >
Showing 1-13 of 13 comments
Per page: 1530 50