Tutorial:Combinator tutorial: Difference between revisions
m (→Logic Gates) |
|||
Line 52: | Line 52: | ||
[[Decider Combinator]] set to "Input = 0" | [[Decider Combinator]] set to "Input = 0" | ||
'''Binary OR''' | '''Binary OR''' | ||
[[Decider Combinator]] set to "Inputs > 0" | [[Decider Combinator]] set to "Inputs > 0" | ||
'''Binary NOR''' | '''Binary NOR''' | ||
Line 72: | Line 64: | ||
[[Decider Combinator]] set to "Inputs = 1" | [[Decider Combinator]] set to "Inputs = 1" | ||
'''Binary AND''' | |||
[[Arithmetic Combinator]] set to "A * B" | |||
'''Binary NAND''' | |||
[[Decider Combinator]] set to "Inputs < 2" | |||
'''Binary XAND''' | '''Binary XAND''' | ||
[[Decider Combinator]] set to "A = B" | |||
== Memory Cells == | == Memory Cells == |
Revision as of 13:38, 17 November 2016
Introduction
Combinator logic is achieved by cross-connecting outputs to inputs in such a way to achieve the desired logic. While advanced logic requires a multitude of combinators, some very useful basic logic can be achieved using only a handful of combinators. Combinator logic works because Factorio only updates the circut network in discrete steps at 60 times per second, such that combinators analyze their logic only once in each step, and then sum the resulting output values on the next step.
When logic values are computed by combinators, the outputs are not recognized by the circuit network until the following step. So when a decider combinator is used to detect a certain input condition, it's output value will not take effect on the circuit network until the next step. This behavior is important to remember and can result in sequencing errors and significant delays when multiple combinators are connected in series.
Red & Green inputs will be summed at all combinators, so if you have a chest connected to a network by red & green its contents will be seen doubled at connected combinators.
When cross-connecting combinators it's good practice to use the unused color to cross-connect, this will split the input and output networks and prevent unwanted inputs from accidentally connecting to a larger circuit network. Combinators will sum the red & green inputs prior to calculation, so either color can be used when wiring the output back to the input.
Input Isolator & Gate
An arithmetic combinator set to (In: Each + 0, Out: Each) can be used to swap wire colors and as an isolator to prevent downstream logic from backfeeding into the circuit network's inputs.
A decider combinator set to (Out: Everything, Input-> Output) will also function as an isolator as long as the set logic condition is true. This can also selectively pass or 'gate' inputs only when desired. This could be used to sequentially poll remote train stations for their chest contents, and include only desired stations.
Set/Reset Latching Switch
You want something to SET a trigger at some quantity, but then STAY on until that quantity hits some other value, the RESET value. You'll need one decider combinator and one arithmetic combinator. Two decider combinators and a constant combinator can also be used for more complex multi-channel conditions.
Setup the first decider combinator to the desired set conditional and to output a 1. Then connect the output to the input of an arithmetic combinator, and configure it to multiply by the bias value, the difference between the set and reset values, and wire the arithmetic output to the input of the decider using the OTHER color wire. The arithmetic output channel MUST be set the same as the decider's input channel. That's it! Whenever your set conditional is reached, the decider will output a '1', and the bias of the arithmetic combinator will be applied. This will 'hold' the output true until the value goes back below the reset point.
Water sensor that sets at 1000 units, resets at 600 units: (Red wire input water tank) -> (Decider Combinator, In:Water > 999 Out:'A' = 1) -> Red wire output, Green wire to -> (Arithmetic Combinator, In:'A' * 400 Out:Water) -> Green wire to Decider Combinator. Whenever input water reaches 1000 units, the decider combinator will output 'A' = 1 until the water goes below 600 units.
Comparing Outputs
Addressing Outposts
Oil Control
Memory
How to store a constant value for later use, either for a basic counter or for more advanced logic. A decider combinator wired output tied to input and configured greater than zero (for positive values), input -> output will 'hold' a value, as long as all other inputs on the network are zero.
Any non-zero input condition will create a basic clock; incrementing the stored value by the sum of all connected input values every cycle. A single pulse of an input will cause a single increment by the pulsed value. Reset to zero occurs whenever the set condition is no longer met, or if a negative pulse equal to the input occurs.
Basic Clocks
Clocks are constructed by having the output of a combinator tied back to its own input, such that every cycle advances its own count. Either the arithmetic combinator or the decider combinator can be used.
An arithmetic combinator tied to itself is fun to watch and will happily run-away, but requires additional control logic to reset.
A self-resetting clock requires just a single decider combinator with output wired to input and configured with Less Than (<) and Input -> Output. When a constant combinator is then connected to the input, every cycle it will count up by the value of the Constant Combinator until the set conditional value is reached, then output a zero which will be summed with the constant combinator, and reset the process.
The clock sequence will not include zero, will begin at the value set by the constant combinator, and will include whatever value eventually causes the conditional to be false. An arithmetic combinator can modify the clock sequence but remember its outputs will occur one cycle later than the clock cycle values.
Pulse Generators
Connecting an additional (=) decider combinator to the output of a basic clock will create a pulse generator, and will pulse a single output every time the clock cycles through the set condition. Any output value can be used, either directly from the clock sequence (input->output), a 1, or some value on a separate logic channel on the circuit network, such as set by a constant combinator. or by the circuit network.
Counter
A counter is used to count the number of input events, and output the sum of that count. Any pulsing input into a decider combinator configured input -> output and wired between output and input will create a counter, but this input must be zero at all other times or else the combinator will run away like a clock. A pulse generator is normally used to accomplish this. Combining several gating decider isolators set with sequential conditionals, a clock, and a pulse generator to the input of a counter will allow remote polling and counting of each isolator's contents.
Logic Gates
Unary NOT
Decider Combinator set to "Input = 0"
Binary OR
Decider Combinator set to "Inputs > 0"
Binary NOR
Decider Combinator set to "Inputs < 1"
Binary XOR
Decider Combinator set to "Inputs = 1"
Binary AND
Arithmetic Combinator set to "A * B"
Binary NAND
Decider Combinator set to "Inputs < 2"
Binary XAND
Decider Combinator set to "A = B"
Memory Cells
Binary Cell
RS NOR Latch File:RS-NOR.png
Advanced Cell
Cell for storing a positiv value:
Connect the desired value as signal 3 on the right side to set the memory cell and connect a negative value as signal 3 to reset the cell.
Address Enable Switch