Conditional counter auto-reset noob question

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
malventano
Filter Inserter
Filter Inserter
Posts: 340
Joined: Thu Apr 27, 2017 4:31 pm
Contact:

Conditional counter auto-reset noob question

Post by malventano »

I've gone through several of the combinator tutorials out there but I'm having a hard time getting this specific thing working. With two decider combinators, I've made a simple circuit that repeatedly counts to 60 (ticks) only when a condition is present. First decider outputs Z=1 when the condition is present. Second decider is looped back to itself, checking Z<60 and outputting Z=input count. Fairly standard setup.

Currently, when the condition clears (Z=0), the counter stops counting and remains at its current value. What I want to happen is for the counter to reset to zero. What's the simplest way to accomplish this? I've found multiple examples where the reset signal comes in from elsewhere (constant combinator, etc), but I can't seem to get it working when the same signal that enabled the counter (Z=1) is also used to reset it (Z=0).

Thanks in advance for the assist.
Allyn Malventano
---
Want to improve fluid flow between pumps / across longer distances? Try my Manifolds mod.

Aeternus
Filter Inserter
Filter Inserter
Posts: 835
Joined: Wed Mar 29, 2017 2:10 am
Contact:

Re: Conditional counter auto-reset noob question

Post by Aeternus »

Reset the counter by adding 60 to Z when the condition clears. This forces the counter to loop back to 0 from whatever value it is currently at.

User avatar
Lav
Filter Inserter
Filter Inserter
Posts: 384
Joined: Mon Mar 27, 2017 10:12 am
Contact:

Re: Conditional counter auto-reset noob question

Post by Lav »

In your situation I would use two arithmetic combinators instead.

First increases the value by 1 and feeds into the second.

Second performs a modulo division (%) by 60 and feeds into the first.

Firedodger
Burner Inserter
Burner Inserter
Posts: 10
Joined: Thu Jun 09, 2016 5:39 am
Contact:

Re: Conditional counter auto-reset noob question

Post by Firedodger »

I am running into the same problem. I have to admit I was never good at math, so eventhough the combinators can't be missed in the game, they require a nasty steep learning curve haha. Hope anyone can explain, perhaps with an example on pictures or something.

I am using the same setup with a mining facility alerting me via a programmable speaker when the ore runs out. I added the combinators with counter to add a delay (otherwhise it gives me a signal everytime the logistics robots collect and push the total ore amount into negative (since at that time the ore is in the air and not in either of the chests).

But now indeed, when it starts counting and the signal is lost due to the ore being above negative again, the counter stops. I tried many ways to figure out what you guys mean, but I am unable to figure it out...

Please try to give an example with pictures or setups so I can learn how these darnest things work hehe :) Thanks!

Firedodger
Burner Inserter
Burner Inserter
Posts: 10
Joined: Thu Jun 09, 2016 5:39 am
Contact:

Re: Conditional counter auto-reset noob question

Post by Firedodger »

After extensive searching I found this video:
https://www.youtube.com/watch?v=2Vpejj292X4

Here it is explained how to tackle the problem. Credits to the video maker and the person who came up with it is mentioned there.

:) Finally I can sleep again haha.

BlakeMW
Filter Inserter
Filter Inserter
Posts: 950
Joined: Thu Jan 21, 2016 9:29 am
Contact:

Re: Conditional counter auto-reset noob question

Post by BlakeMW »

The counter setup I use is what I call the "pistol method"

You wire a decider combinator to itself, and set it up as follows:

Input: pistol = 0
Output: Everything: input count

Everything: input count, means that it will store all input values, it is a basic universal memory cell / accumulator.
Pistol is the reset signal: as long as pistol is 0, it will store all values. If pistol is non-zero all stored values are wiped. Resetting the signal involves a decider combinator set up like:

Input: Z = 0:
Output: pistol 1

You can of course use any reset signal you wish, I like pistol because it is a pretty useless signal and thematically appropriate.

Now the pistol method probably won't result in the lowest possible combinator counts: but it is a very useful building block especially when there are multiple possible reset conditions - it is guaranteed to reset when the pistol signal is sent. So the way I would solve your problem would be to use 4 combinators as such:
Constant Combinator: Z = 1 (clock)
Decider Combinator: Pistol = 0: Everything = input count (memory cell)
Decider Combinator: Z = 0: pistol = 1 (reset 1)
Decider Combinator: Z > 60: pistol = 1 (reset 2)

Post Reply

Return to “Gameplay Help”