Stored Value in circuit non-incrementing

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
apothecary
Manual Inserter
Manual Inserter
Posts: 2
Joined: Fri Aug 09, 2019 11:30 pm
Contact:

Stored Value in circuit non-incrementing

Post by apothecary »

Hello,

I am trying to implement a stored value in a circuit and I am having a bit of trouble. The standard implementations I have found are basically counters that increase using the loop of input to output on a combinator.

I wish to store a value that is transmitted on a circuit and not have it accumulate. It would work fine for me if the first value sent was stored and I needed to send a reset signal to clear whatever that first value was.

As a simple explanation of what I am trying to make work imagine the following:

Constant Comb outputs Y with a value of 30.

Arithmetic Comb Accepts Y + 0 and converts that signal to A with a value of 30.

I now wish to store that value for A even if I delete the Constant Combinator. Obviously since the combinators output their values every single tick, I can't simply loop this back on another combinator or the value with increment like crazy. I basically want to store that initial value of Y until I do something else to cause it to reset. Although I am using a constant combinator in my example, my ultimate solution will not be a constant but a variable Y that I wish to store.

If there is a guide or example of this and someone could point me there I would really appreciate it. I cannot seem to wrap my head around how to make this work and I have a feeling the solution is pretty straightforward.


EDIT: I believe I have found the solution Here. It was found as a simpler solution to what I felt I wanted but was impossible for me to understand. This example was very straightforward.

Leaving this here in case it helps anyone else.

slippycheeze
Filter Inserter
Filter Inserter
Posts: 587
Joined: Sun Jun 09, 2019 10:40 pm
Contact:

Re: Stored Value in circuit non-incrementing

Post by slippycheeze »

I think you will find this solution is the current state of the art, being a one-cycle save memory that supports both multiple individually addressable memory cells on the same input/output line, and reserves only one control signal. All other signals, and all values of those signals, are correctly preserved. It can also act as a memory cell for control signal presence/absence regardless of value, and has extremely low read latency, as well as while filtering the control signal from the output.

This does not suffer the standard shortfalls: it requires only 1 tick to save, so works correctly with single tick pulse inputs, and it does not have any issue with either positive or negative numbers, storing the full 2^32 - 1 range (excluding zero, which is always implicitly stored) for every signal other than the one control signal.

The root, as with any memory cell, is simply that you wire the output to the input of a decider or arithmetic combinator, and set it so that it will output signal(s) with the input value unmodified, usually one of <each + 0 => each>, <each * 1 => each>, or <if <condition> => each as input value>, the last being a memory with reset. The remaining two combinators in this cell are there to improve write behaviour, and to filter the control signal from storage.

Post Reply

Return to “Gameplay Help”