Imagine you have a chest or a warehouse that stores all the coal (or another resource) you currently not need and this warehouse acts as a resource buffer.
When there is a minor shortage somewhere, the resources of the warehouse are instantly used to compensate the loss. But when there is a constant shortage, the buffer runs empty somewhere in the future.
In this moment something is wrong, because the number of currenly produced resources is too low. If we don't react to this, at some time the buffer will be empty and we are maybe in trouble.
Let's say you check the number of the resource every second and you get the following sequence:
100 - 105 - 108 - 106 - 110 - 112 - 115 - 113 - 116 - 120 - 122
This resource is doing great because the number of resources increases over time (last value of 122 is larger than the first value of 100).
A simple approach would be now: After some interval, save the current value and compare it for the next seconds with the current live value. If the current live value is higher than the saved value, show a green signal or if not, show a red signal.
If we save the value every 5 seconds, it will save at 100, 112 and 122:
100 - 105 - 108 - 106 - 110 - 112 - 115 - 113 - 116 - 120 - 122
This seems to work: Every following number after 100 is higher than 100. Every following number after 112 is higher than 112. And so on.
But what happens if we save at the point 108? The following number 106 is lower, so it would produce a short red signal. This is not good. It should be green, because this resource is doing great!
A better approach would be: Save the current value and after some time, save it to another memory cell, before we save again the current value. Now we have two values with different timestamps, that are always 5 seconds apart and when we compare them, we can tell if the resource number is increasing over the specified time. We only need to choose an interval that is large enough to compensate normal fluctuations.
In our example above this would mean: Save the value 100 and after 5 seconds compare it to the current value, which is then saved again:
Saved: 100, check against 112: OK
Saved: 112, check against 122: OK
In fact, we can now do the check at a random position and the result is always OK.
Here is the problematic example from above:
Saved: 108, check against 113: OK
Much, much better!
Now it's time to produce a corresponding signal circuit: We need a timer and two memory cells, that we then compare against each other.
But we must keep in mind two special conditions:
In both situations a red light should be shown because something is wrong.
To address this, we simply check for equal numbers, too, and say: If the new value is equal or lighter than the old value, a red light is shown. If not, a green light is shown.
Ok, let's begin with the clock ...
The constant combinator sends a time-signal with the value of 1 every game tick (I used the "time signal" from the mod "Dectorio", but you can also use any vanilla signal, too). Because our clock combinator is wired to itself, the time value will increase every game tick (the value of 1 is added to the current signal for every game tick).
With the middle decider combinator we check if the time is up. When the time is up, a second signal is sent, which resets the clock (the "alarm signal" is also from the mod "Dectorio").
The right combinator holds the current time. Because it will output the current time only when the alarm signal isn't set, to the contrary the time will reset when the alarm signal IS set.
This setup turns our clock into a timer: In the example the clocks count to 1000 and is then resetted.
(1000 ticks = 1000/60 seconds = ~17 seconds).
Let's see if this works ...
Nice! At 1k you can see the flash from the alarm signal when the clock is resetted.
Now we need a memory cell to store the current number of a specified resource:
First, we convert the coal resource signal to our own virtual signal (with the left combinator). This will a) prevent mixing up signals and b) makes the initial setup easier because you have a central point where you can choose the desired resource.
In the example we convert the resource "coal" (which is delivered via the left green cable) to the virtual signal "1".
The middle combinator checks if we reached the end of the timer. In this moment we read the current value of signal "1" (which is the converted coal signal) for exactly 1 game tick. The value is then holded by the right combinator, because it is wired to itself.
When we read the current resource value at game tick 1000, we don't want the current memory value to be added, so we output the memory only before (and after) game tick 1000.
Let's see if this works. We connect the input of the constant combinator to our resource and hover the mouse over the right combinator, which holds the saved value:
Great! The amount of signal "1" is holded until the time is over. Then it is updated with the current value (from 503 to 545).
Now we need a second memory cell which copies the last saved value to another memory cell, so we can compare both numbers.
The memory cell is configured the same as the first one, but this time, instead of getting the coal signal as input, we get the last value of signal "1" as input and convert it to signal "2".
Now we have the signals "1" and "2". These are our saved coal values which are always 1000 game ticks apart. We compare these signals and turn this into a red or green light signal:
Let's check the results. I added some tube displays to see the live values: The big display shows the current resource number (in our example coal), the left small display shows memory cell 1 and the right shows memory cell 2. And the white light flashes when the memory is updated.
As long as the value increases between the intervals, short fluctuations are compensated and the light is green. You can see that the content from memory cell 1 goes to memory cell 2 and memory cell 1 is updated with the current live value. At around 129 (in the video at 00:55) the value is stagnating/decreasing and a red light is shown at the end of the next interval.
For some signals the mod Dectorio is needed or alternatively you can change the signals to vanilla signals.Click to select the whole blueprint:
For resources that are delivered in big bursts within large time intervals (e.g. resources delivered with a train), you may need to increase the time value, because the resource numbers are fluctuating much more.
If you want to control the length of the timer with a single click, you can use a constant combinator which sends e.g. signal "T" with the value "1000" and then use this signal for the time checks.
END OF TUTORIAL.
Written by Tobias Wiersch. Factorio 0.17. Last change: 2019-03-08 (V1)
Back to index page