An obscure circuitry behavior

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Yuki_Nagato
Inserter
Inserter
Posts: 23
Joined: Thu Oct 12, 2023 10:08 pm
Contact:

An obscure circuitry behavior

Post by Yuki_Nagato »

Currently Problamtic Setup
When making an asteriod crusher recycling design, I came to this weird problem that instead of setting the recipe to reprocessing, it sets the recipe to crushing.
2025-05-16_16-07-52.png
2025-05-16_16-07-52.png (2.89 MiB) Viewed 691 times
This setup now works most of the time, but sometimes crush the asteroid to get ice, iron or carbon. I added three splitter to help me tell if it produced them.
It happens randomly, more tiled machines are stuck faster, however I didn't observe it happen when I only use top row of machines (It might just because of luck).

Analyse
First I'll explain what these circuits does:
1. Constant combinator are coded recipes (see here for a introduction of recipe selector.)
2. Decider combinator near constant combinator is recipe selector that selects an recipe when machine and inserter is empty (condition 1 in "AND" group, condition 2 is recipe code, condition 3 is found ingredient).
3. The other decider combinator is a register that locks recipe when machine or inserter is not empty.

I've noticed a place where things could go wrong:
When the crusher has no more ingredients, and output inserters are taking out outputs, at that tick register decider combinator loses any "stock" input signal, at the same time input inserter picked up a new ingredient. The next tick recipe selector decider combinator has no output because the inserter has item in it, the register decider loses recipe signal and the machine is set recipe by inserter item.
This setup don't always have a recipe selected from decider combinator, giving a chance for inserter 1 tick pick chance to set a crushing recipe. The setup in original post always have a recipe signal, so it won't accept any item signal as recipe.

Here is a tick by tick video I accidentally captured (after going tick by tick for 14 hours? accident?)
Factorio - 2025-05-16 16-44-31.mp4
(59.5 MiB) Downloaded 26 times
I roughly think that add a constant recipe signal (with lowest priority) can brute force solve this problem, but I don't like this. Any ideas?
(Tried to brute force add a constant recipe signal, it's not easy and are beyond my size limit of this design)
Further Improvements
I have some other problem wants to get improvement.
1. Check if there is any other problem that may break this design?
2. A more graceful way to handle that 1tick window instead of constant recipe signal?
3. In this design, the recipe code constant are hooked to a combinator that I can't find a way to just use one wire, but two wires. So I have to seperate each recipe code constant for each tiled machine. Can I optimize the wiring to let them use the same combinator to share the constant without interference? (I think adding a diode is not worth it. It's bigger and consume power.)

Edit: I actually solved this specfic quirk and even saved one more wire color, I'll explain what happend when I have time to.
Edit 2: Finally I made this working version which satisfies my requirements. It still has a lot room for improvement, but it's working well now.

I "abused" recipe selector decider combinator to save one wire color on crusher, and added a blocking signal with the extra wire color. Thankfully all crusher can share this constant signal.
I intuitively feels that I can even let recipe selector decider combinator share recipe code constant signal using a similiar method, but I will leave it for now. (Sketch idea: use register decider combinator to double as a encoder to encode items from conveyer to other differentiable signals than working items(items inside machine & inserter), so that recipe selector decider combinator can use one wire color to take conveyer item and working item. Then I can use another color to share recipe code.)

Original Post
The below blueprint has a mistake, and the analyse based on this blueprint is not the real reason. However this behavior do exist randomly, I'm doing more investage.

Blueprints first:
Working:

Not Working:


When making an asteriod crusher recycling design, I came to this weird problem that instead of setting the recipe to reprocessing, it sets the recipe to crushing. The idea that came to me first is the execution order of circuitry, so I flipped wire color and it worked.
As long as the behaviour stays consistent with specific wire, I'm fine with it. I understand this kind of execution order effect is reasonable about programming, but I think it's worth pointing this out.

Below are some explanation and analyse:
2025-05-16_11-08-20.png
2025-05-16_11-08-20.png (996.87 KiB) Viewed 777 times
2025-05-16_11-08-36.png
2025-05-16_11-08-36.png (956.08 KiB) Viewed 777 times
1. Selector combinator randomly chooses a recipe.
2. If there is nothing inside machine and inserter, change recipe, otherwise, use a register to lock recipe.

3. When the ingredient of that recipe is in front of the inserter, these happens:
Tick 1 - selector combinator changed to this recipe
Tick 2 - decider combinator A changed it's output to this recipe
Tick 3 - machine sets this recipe
Tick 4~k - the inserter grabs the item(takes different time due to coveyer-inserter interaction, assume ends at tick 7)
Tick 7 - decider combinator B now have to inputs: the recipe and the ingredient
Tick 8 - This is where discrepancy happens: in the not working version decider A disabled its output because its requirement are not met, and decider B loses recipe input, machine is set to make ingredient(crushing recipe); in the working version decider B's requirement are satisfied so it stores the recipe signal, the decider A also loses its output, but the recipe is locked.

Another note about this design: machine set recipe prefers recipe signal, so if both an item and a recipe signal exists, they always pick recipe signal's reciple.
Side note: I actually found this problem when improving this design, the better designs still need some polishing(most of the time was spent on this problem).
Last edited by Yuki_Nagato on Sun May 18, 2025 1:26 am, edited 15 times in total.
mmmPI
Smart Inserter
Smart Inserter
Posts: 4540
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: An obscure circuitry behavior, possibly due to execution order?

Post by mmmPI »

Yuki_Nagato wrote: Fri May 16, 2025 3:07 am Side note: I actually found this problem when improving this design, the better designs still need some polishing(most of the time was spent on this problem).
I think the difference between working and not working version is the wire are inverted green<=>red but the settings inside the left decider combinator are "red" in the 2 versions.
Yuki_Nagato wrote: Fri May 16, 2025 3:07 am Another note about this design: machine set recipe prefers recipe signal, so if both an item and a recipe signal exists, they always pick recipe signal's reciple.
That's interesting, i don't understand the priority when you send 3 receipe signals =>

1) heavy oil cracking
2) basic oil processing
3) solid fuel from petroleum gas

It seem weird that the one in the middle of the Gui has the priority when there is one on the left and one on the right. I'm lost there
Yuki_Nagato
Inserter
Inserter
Posts: 23
Joined: Thu Oct 12, 2023 10:08 pm
Contact:

Re: An obscure circuitry behavior, possibly due to execution order?

Post by Yuki_Nagato »

mmmPI wrote: Fri May 16, 2025 5:43 amI think the difference between working and not working version is the wire are inverted green<=>red but the settings inside the left decider combinator are "red" in the 2 versions.
Yes, that is an oversight when testing, and that's why I can consistently get a not working version XD
However, I still find this behaviour randomly when tiled/rotated, now I'm not sure why this is happening. But it is random, not so consistent as what my wrong setting caused. I did more test but have no clue for now. I may need another 10 hour or something to give better analyse of this.
After another 2 hours, I edited original post to give another problematic design, and seem to find a reason why it breaks :D

Speaking of multiple recipe signals: they work as in-game described that first signal gets used. Decider combinator outputs signal in the order of which satisfies the condition, constant combinator outputs signal in the order of settings from left to right.
(I did more test and found out that basic oil processing>advanced oil processing>simple coal liqufication, and heavy oil cracking>solid fuel from petroleum gas. It seems that they always work in order of factoriopedia)

An interesting example of this feature is a priority recipe selector:

Code: Select all

0eNrVWe1P20YY/1cif9o0B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QYp6lUp3EleDnXvnt1f+5WuPKykAp3Flsvnoi74OFG0FhsNX8JXl3mxsHc89buSnh/rbX7PLw+u39vtvVmLby0M07HaeQ3C65ff/tNe/dqFFzEAptg8d+z3QTtXzfD+4/aW6v7s9eD+Wb7r8fB0jURE2CAawIGLFvNBQ52vtmfvpASNuH1jc7aT2JsnH73fTd168WN1oub+2vNoLkoEgn7COrTzfDqIpgFOy95gu3X7b3teMZLC61Xd4O9v4PlW3GCLjI1BfPtPL7UebMKGflcm6vtzafB9t1w4Um4srd/559waz18uh7c2FRTrdc3g8eXg8aPgmvBQfDzZnjvQTi7Ea4+C1can7V2Fzpvltrbt4PfNiFD1gvmAeyD4FojvNQI9pZhLLz9fP/2s89HUsG1h+HKFmfo2e/h/aVgcadzZa+z/md7YzdKKMCFf8yGDx4FzeVg684X4b1muN7ozF/mV5BiRBmwxRp9ly2W1r/F0j6eHdbbO+vQgijZqdHGFUK4ZhnzU5AIYjuQxeGnY36f7XkuOtZ0mBWn81DclBT508SFNDMITpp9HMVY4nOoMnT1i2/5KUysHoNN1YMacEBD1kwYxohV0hU0iX4gtG/ZzmUyR5bP+MR2MKmSb086DH36s5qIqjwDvhz6uayaVXMqFDa60qOrPFyNxlc5GNPgSkueatFYDq70yC4/AfE80lVMf5+dEZ8w6sO+LZWABkuwzBnqd/9Szn1Uzl2Xc9fk3PNy7jk596yUe0Yu+Znko5KEajQ51WhyqtHkVKPJqUaTU40mpxpNSjWanGp0OdXocqrR5VSjy6lGl1ONLqcaXU41upRqTuY9Ib7s8q/vyW8qqmKjIraT42jKxTbsBx2WmiFeOQVGDuNfAFVlGjM3yquP5sa0sTF9VM9k9YxWr/8HncF7zg==
2025-05-16_14-42-03.png
2025-05-16_14-42-03.png (209.78 KiB) Viewed 724 times
1. Each "OR" seperates "AND" group, inside each "AND" group the first condition is "recipe code" that is unique signal strength to that signal
2. the first condition always satisfies, to select that recipe code as yellow "each signal"
3. the other condition inside each "AND" group are recipe requirements, here is "I have ingredient and I need output"
4. when a "AND" group is satisfied, decider combinator's output "each signal" will contain the recipe code.
5. when multiple "AND" group is satisfied, multiple recipe code are output, and their order is from above to bottom. So this works as a priority combined with set recipe.(get iron first, then carbon, then ice)

Note: as a suggestion it's usually needed to set a high value of recipe code, to prevent other signal (usually item stock) happen to equal this value and interfere.
More, it's good to set a negative value of recipe code, as most of the time item stock won't be negative.
Further more, set a big negative value, as logisitic network can get negative item stock when robots are taking item, or some other calculation happens.
But negative signal does not set recipe, so the selected result need to be fliped.
Last edited by Yuki_Nagato on Fri May 16, 2025 10:42 am, edited 1 time in total.
mrkev
Long Handed Inserter
Long Handed Inserter
Posts: 60
Joined: Wed Apr 23, 2025 9:44 pm
Contact:

Re: An obscure circuitry behavior

Post by mrkev »

Yuki_Nagato wrote: Fri May 16, 2025 3:07 am
Currently Problamtic Setup
When making an asteriod crusher recycling design, I came to this weird problem that instead of setting the recipe to reprocessing, it sets the recipe to crushing.
The whole problem is likely caused by a simple mechanic, that you might not be aware of. When you send a signal of asteroid to the crusher, it will set it's recipe to crushing of that asteroid:


So, when the inserter picks up an asteroid and its signal is read one tick before the correct recipe is set, it will set the recipe to crushing. You'll have to make sure that you can't get any other signal, than the reprocessing to those crushers. In other words, you can't have inputs (inserters and belts) connected directly to the crushers.
Yuki_Nagato
Inserter
Inserter
Posts: 23
Joined: Thu Oct 12, 2023 10:08 pm
Contact:

Re: An obscure circuitry behavior

Post by Yuki_Nagato »

mrkev wrote: Fri May 16, 2025 10:16 am The whole problem is likely caused by a simple mechanic, that you might not be aware of. When you send a signal of asteroid to the crusher, it will set it's recipe to crushing of that asteroid:
Thanks for your reply! You are correct about this.

Though it feels "unsafe", it is intentional. Connecting the inserter to the machine to count item is feasible when a) a recipe signal will override machine recipe (recipe signal takes precedence); b) some diode is used properly. The main advantage to do this is save one wire color to do extra logic (I'm already tight with wire colors here).
But in the end, it is unsafe and this time it really caused the trouble. My design was a revision of older designs, and the older design always have a recipe signal to override machine recipe, so this is not a problem. Now that I select recipe based on ingredient, chances are sometimes no recipe is selected and inserter item can set the recipe. So you are correct!

Besides add a constant recipe signal to override, I just came up with two new methods:
A) let the register also check output inserters' stock for locking. This method makes that machine idle when outputing last outputs, so less efficient.
B) Seperate inserter and machine item signal line, which need two colors or more combinators. But I think I figured out a way to fit in my design without additional combinators, it will need a refactor of current design. I will post it here after I have time to test :D

By the way, to be honest, this new design is not a strict improvement from the old design, the old design still uses less space. I can fit some circuitry inside belts (using underground belts) so just maybe, it may not need more space with some better recipe response.
Tertius
Smart Inserter
Smart Inserter
Posts: 1319
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: An obscure circuitry behavior, possibly due to execution order?

Post by Tertius »

mmmPI wrote: Fri May 16, 2025 5:43 am That's interesting, i don't understand the priority when you send 3 receipe signals =>

1) heavy oil cracking
2) basic oil processing
3) solid fuel from petroleum gas
There's no issue.
If you feed a chemical plant with all of these 3 recipes, heavy oil cracking is selected. It's the leftmost recipe in the GUI valid for a chemical plant. Basic oil processing isn't valid for a chemical plant.
If you feed a refinery with all of these 3 recipes, basic oil processing is selected. It's the leftmost recipe in the GUI that's valid for a refinery. The others are not valid for a chemical plant.

However, the recipe selection for the asteroid crusher isn't clear to me.
  • If you feed an asteroid crushing recipe and a reprocessing recipe, the crushing recipe is selected. This is expected, because the crushing recipe is more to the left in the signal selection GUI.
  • If you feed an asteroid and a reprocessing recipe, the reprocessing recipe is selected. This is unexpected, because all the asteroid are more to the left in the signal selection GUI than the reprocessing recipes. Also all the crushing recipes are more to the left. So I expect the crushing recipe is selected, but it isn't.
  • If you feed all 3, the crushing recipe is selected (it's the recipe that's selected, not the crushing for the given asteroid). This is also unexpected. The crushing for the asteroid should be selected, since it's more to the left in the GUI than the recipes. There seems some internal tweaking within the game engine.
Example:
05-16-2025, 12-39-06.png
05-16-2025, 12-39-06.png (85.99 KiB) Viewed 634 times
The asteroid seems to be ignored in the last option. If internally changed to its crushing recipe, the recipe in the example should have priority, because carbonic comes first in the order, but the oxide crushing recipe is selected.

I can only guess it's some kind of helping functionality for the player to avoid crushing if no explicit crushing recipe is being sent but a reprocessing recipe and some asteroid signal read from belt or wherever. Or some issue with separating outgoing signals from incoming signals to be able to set a recipe when there's also items in the crusher with higher priority. Could be worth a bug report to examine. I remember the devs slightly cursed situations like this.
mmmPI
Smart Inserter
Smart Inserter
Posts: 4540
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

Re: An obscure circuitry behavior, possibly due to execution order?

Post by mmmPI »

Tertius wrote: Fri May 16, 2025 10:48 am There's no issue.
If you feed a chemical plant with all of these 3 recipes, heavy oil cracking is selected. It's the leftmost recipe in the GUI valid for a chemical plant. Basic oil processing isn't valid for a chemical plant.

If you feed a refinery with all of these 3 recipes, basic oil processing is selected. It's the leftmost recipe in the GUI that's valid for a refinery. The others are not valid for a chemical plant.
I had mistook the icon "basic oil processing" for the simple recipe that makes petrolum gas to plastic when it's in fact crude oil to petroleum gas and made into refinery. Make sense then , the left most receipe has priority , one is invalid .
mrkev
Long Handed Inserter
Long Handed Inserter
Posts: 60
Joined: Wed Apr 23, 2025 9:44 pm
Contact:

Re: An obscure circuitry behavior, possibly due to execution order?

Post by mrkev »

Tertius wrote: Fri May 16, 2025 10:48 am I can only guess it's some kind of helping functionality for the player to avoid crushing if no explicit crushing recipe is being sent but a reprocessing recipe and some asteroid signal read from belt or wherever.
- This. It's likely made this way so you can set crushers recipe directly from the belt content, but it's intentionaly given lower priority over other recipes.
Yuki_Nagato wrote: Fri May 16, 2025 10:41 am Though it feels "unsafe", it is intentional. Connecting the inserter to the machine to count item is feasible when a) a recipe signal will override machine recipe (recipe signal takes precedence); b) some diode is used properly. The main advantage to do this is save one wire color to do extra logic (I'm already tight with wire colors here).
The whole problem is, that this creates a hazard. Signals passed through circuits take one extra tick, so in some rare cases, you'll get just the asteroid signal and nothing else. When the inserter inserts that asteroid before the signal can be processed, you'll end up with crushing instead of reprocessing. It might work 100% if you'd use slower inserters, but that's IMHO not a good solution (although I'm using it in Gleba, for nutrients inserters that are supplying normal nutrients for higher quality biolab production). Another possible solution might be to sense also the belt one tile before the inserters, so the recipe is set before it's picked up.
Yuki_Nagato
Inserter
Inserter
Posts: 23
Joined: Thu Oct 12, 2023 10:08 pm
Contact:

Re: An obscure circuitry behavior, possibly due to execution order?

Post by Yuki_Nagato »

mrkev wrote: Fri May 16, 2025 11:17 am The whole problem is, that this creates a hazard.
Yes, definitely. This is what lead me to this post and took me hours to fix. I edited original post again to include my current working solution: Add a block signal to completely prevent crushing recipes from happening.
mrkev wrote: Fri May 16, 2025 11:17 am It might work 100% if you'd use slower inserters, but that's IMHO not a good solution
Indeed! I've been utilizing this for a lot of scenario. In fact this design is from combining two of my previous designs. One uses slow inserter and on-demand recipe code, the other one uses always-on recipe code. This new design is focused on extreme machine utilization so slow inserter works bad with fast belt, and always-on recipe waste a lot of time polling the recipe. (By extreme: that is, this new design is not meaningfully better, just theoretically let the machine idle the least time.)
mrkev wrote: Fri May 16, 2025 11:17 am Another possible solution might be to sense also the belt one tile before the inserters, so the recipe is set before it's picked up.
I made some sketch designs about this, generally it didn't work better than current solution. Besides, when a design is already so tight with space requirement, it's worthing noticing that read belt by tile takes space(because we can't read from underground belt tiles).
Let me clarify my space requirement: 3 tile spacing between each row of crusher, so I can fit beacons in it. This includes combinators.
You can look this blueprint to see that I need to squeeze space from belt to put combinators there, and even reading three more conveyers it will be impossible to fit. (Yes, I still have some room for a thing, I think puting that crushing recipe blocking constant combinator there would be good)


Generally your idea are very good principles! I can prove this!
Yuki_Nagato
Inserter
Inserter
Posts: 23
Joined: Thu Oct 12, 2023 10:08 pm
Contact:

Re: An obscure circuitry behavior, possibly due to execution order?

Post by Yuki_Nagato »

Tertius wrote: Fri May 16, 2025 10:48 am If you feed all 3, the crushing recipe is selected (it's the recipe that's selected, not the crushing for the given asteroid). This is also unexpected. The crushing for the asteroid should be selected, since it's more to the left in the GUI than the recipes. There seems some internal tweaking within the game engine.
When any valid recipe signal is present (the machine can craft this recipe), set recipe ignores item signal. Only when no valid recipe signal is present, item signals are considered.
As within the same group of signals (recipe/item), they are in the order of Factoriopedia.
Post Reply

Return to “Gameplay Help”