Simple way to cap a circuit signal at a maximum value?

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
User avatar
Mad Inventor
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sun Mar 13, 2016 1:10 am
Contact:

Simple way to cap a circuit signal at a maximum value?

Post by Mad Inventor »

There's probably a very simple answer, but it's driving me crazy. How do I set a signal value to a maximum if it is above the maximum, but otherwise leave it alone?
If I use a decider combinator with "less than or equal" it will output the value if it is equal to or below the maximum, but if the value is above the max, it will output nothing, not the maximum I want.
If I add a second, parallel combinator with "greater than", I can't have it output the maximum because a decider can only output the incoming value (which is above the maximum) or 1.
If I use a different signal (such as a gray color signal when I'm trying to cap the iron ore signal) with a constant combinator for the maximum, then a decider can be set to output the "input count" of that different signal if the one I'm trying to cap is higher. And then I will need to somehow swap it back to having that value on the original channel.
With all the improvements that were made to circuits/combinators in 2.0 (or even ones before that I missed) there's got to be a way to set a maximum value without using 3-5 different combinators.
brittlecracker
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat Nov 09, 2024 10:09 pm
Contact:

Re: Simple way to cap a circuit signal at a maximum value?

Post by brittlecracker »

Hi! I have thought a little about it and can't find a clever way to do it. A naive way is to use two deciders and an arithmethic combinator:
  • First decider reads input signal, if less than max, output that signal.
  • Second decider reads input signal, if greater or equal to max, output 1 of that signal. Output of that connects to input of arithmetic combinator, which multiplies the value by the max and outputs it.
  • Join the outputs of first decider and the arithmetic combinator and you will have the input value capped at max.
Would that work for you? If so, here's a parameterized blueprint for that. It also uses a single constant combinator (on the other circuit color) that sets the max, so it's easier to update after the blueprint is placed.

BaggyK
Inserter
Inserter
Posts: 42
Joined: Fri Mar 01, 2019 12:22 pm
Contact:

Re: Simple way to cap a circuit signal at a maximum value?

Post by BaggyK »

Use a constant combinator to feed in the maximum value, then have two deciders one for less than the maximum which outputs the original item count, the other for greater or equal to the maximum which outputs the maximum input.
mergele
Fast Inserter
Fast Inserter
Posts: 202
Joined: Sat Aug 20, 2016 5:45 am
Contact:

Re: Simple way to cap a circuit signal at a maximum value?

Post by mergele »

That also needs a translation to a help signal and a delay to keep synchronous., bringing it up to 5 combinators.

This setup does it with 4
3.png
3.png (4.35 MiB) Viewed 1269 times
You can set the maximum per constant combinator feeding a virtual signal in, making setting it up and using it multiple times easier, but then you need a decoupler on the input to prevent side effects, so since I don't know your requirements I left that off.
Nidan
Filter Inserter
Filter Inserter
Posts: 286
Joined: Sat Nov 21, 2015 1:40 am
Contact:

Re: Simple way to cap a circuit signal at a maximum value?

Post by Nidan »

The OP got very close to the solution. Instead of putting the maximum directly into the deciders, put it into a constant combinator connected to both deciders, using the other wire color.
Decider 1: Each red <= Each green, output Each red
Decider 2: Each red > Each green, output Each green
You can replace Each with the actual signal you're interested in if you don't want nor need the vectorized version.
arl85
Fast Inserter
Fast Inserter
Posts: 182
Joined: Tue Jun 10, 2014 7:08 am
Contact:

Re: Simple way to cap a circuit signal at a maximum value?

Post by arl85 »

If I'm interessed in capping a single signal, I just found a simply method
immagine.png
immagine.png (71.13 KiB) Viewed 1109 times
constant combinator with "up arrow" as maximum value (in this case DOT signal is for demo purpose, the signal I want to cap)
immagine.png
immagine.png (337.72 KiB) Viewed 1109 times
connected to a selector combinator outputting first signal ordered ascending (so minimum value)
immagine.png
immagine.png (244.31 KiB) Viewed 1109 times
plus a convertor to go back to my signal
immagine.png
immagine.png (301 KiB) Viewed 1109 times

Please note that both my solution and the previous blueprint work only if the signal you want to cap is > 0; in case of signal = 0, in both cases max will be returned

edit: an improved version that works even when no input signal is provided.



connect input signal here
immagine.png
immagine.png (142.66 KiB) Viewed 1061 times
Post Reply

Return to “Gameplay Help”