ZeroGravitas
The Destroyer
It's entirely possible in Terraria, now, to make various real world logic circuits by following circuit diagrams that use traditional electronic logic gates *. The gates manage to emulate the logic states. Here's an example of your typical "D-Type" (D stands for data) circuit (from wikipedia):
When a "clock" signal comes in (state changes to on) the logic state on the data input gets transferred to "Q" (and Q-bar is set to the opposite of that). The data is latched (or loaded) into this device's simple memory. Looping the Q-bar output back to the data input then causes the output state to flip on every other state change of the clock input. (Since this is a "positive edge" triggered setup, change to off state is ignored.)
In Terraria this NAND gate assembly functions the same and looks like this (with the long yellow wire at bottom providing the toggle feedback, not shown above):
I've tried to lay it out in the same way as the top diagram, for demonstration purposes.
However. In their infinite wisdom, the devs have provided a somewhat more compact way to achieve the same function. A kind of ultimate flip-flop, thus:
The output torch will change state every other time the input-switch-linked torch does. This is thanks to the "faulty logic lamp", which magically converts any logic gate into a randomizer: inputs to the faulty lamp (always top of the stack) will produce an output a percentage of the time depending on the number of regular lamps that are currently turned on. There can be many lamps stacked up in different states to tune this probability, but with only 1 lamp this means it will always relay the input signal to output when the lamp is on (100%) and never when it's off (0%). Thus by connecting both the faulty lamp (input) and the only probability-adjusting lamp together, every other input signal will be ignored as the probability function toggles between 100% and 0% (of relaying the input change signal).
Anyway, this super-simple setup makes for a very compact and effective binary counter: just a string of flip-flops, each dividing by 2.
This setup seems unbeatable - not only is it tiny and simple, it should also operate and count as fast as you can toggle the input, multiple times within a single tick(!), as the wire activation ripples through it. Bye-bye dusty, old skeleton counter!
[doublepost=1464089760,1464083723][/doublepost]To go a step further in showing the faulty lamp gate's flexibility, here's a counter with a reset line integrated and an (accidental) shifter line, all with just 1 lamp randomisers:
Their function and interactions are pretty subtle (and somewhat unintuitive, I think). The counters only count correctly if the output is inverted (i.e. the torches are in the opposite state to the gate input lamps they are connected to).
This means the reset line actually sets the count to maximum value (all torches on), as opposed to zero. But inverting the lamp inputs of the reset line did not correct this, instead this created a shifter (multiply by 2, effectively), that moves each bit of the count pattern one to the right (useful for various binary math operations). An interaction between the attempted reset and the count circuits, I guess (?).
Note: DicemanX's AND gate based reset mechanism functionedpoorly when in place, here, taking repeated activations (and much smoke) to clear all the bits. (As with most things, I imagine there will be work-arounds or better designs.) ...fine, too, once setup correctly (although still produce a bunch of smoke).
Also, regarding the " * " in the top of the post: some logic gate latch types work with Terraria wiring, while others seem to fail in certain configuration. This "gated SR latch" seems to function ok:
It transfers the logic level presented at the top or bottom inputs to the opposite position output, only when the middle switch (gate) is set to enabled.
But others I failed to make function correctly, with smoke emanating from gates due to the loop back of outputs to inputs. (Maybe I was being dumb though.)
When a "clock" signal comes in (state changes to on) the logic state on the data input gets transferred to "Q" (and Q-bar is set to the opposite of that). The data is latched (or loaded) into this device's simple memory. Looping the Q-bar output back to the data input then causes the output state to flip on every other state change of the clock input. (Since this is a "positive edge" triggered setup, change to off state is ignored.)
In Terraria this NAND gate assembly functions the same and looks like this (with the long yellow wire at bottom providing the toggle feedback, not shown above):
I've tried to lay it out in the same way as the top diagram, for demonstration purposes.
However. In their infinite wisdom, the devs have provided a somewhat more compact way to achieve the same function. A kind of ultimate flip-flop, thus:
The output torch will change state every other time the input-switch-linked torch does. This is thanks to the "faulty logic lamp", which magically converts any logic gate into a randomizer: inputs to the faulty lamp (always top of the stack) will produce an output a percentage of the time depending on the number of regular lamps that are currently turned on. There can be many lamps stacked up in different states to tune this probability, but with only 1 lamp this means it will always relay the input signal to output when the lamp is on (100%) and never when it's off (0%). Thus by connecting both the faulty lamp (input) and the only probability-adjusting lamp together, every other input signal will be ignored as the probability function toggles between 100% and 0% (of relaying the input change signal).
Anyway, this super-simple setup makes for a very compact and effective binary counter: just a string of flip-flops, each dividing by 2.
This setup seems unbeatable - not only is it tiny and simple, it should also operate and count as fast as you can toggle the input, multiple times within a single tick(!), as the wire activation ripples through it. Bye-bye dusty, old skeleton counter!
[doublepost=1464089760,1464083723][/doublepost]To go a step further in showing the faulty lamp gate's flexibility, here's a counter with a reset line integrated and an (accidental) shifter line, all with just 1 lamp randomisers:
Their function and interactions are pretty subtle (and somewhat unintuitive, I think). The counters only count correctly if the output is inverted (i.e. the torches are in the opposite state to the gate input lamps they are connected to).
This means the reset line actually sets the count to maximum value (all torches on), as opposed to zero. But inverting the lamp inputs of the reset line did not correct this, instead this created a shifter (multiply by 2, effectively), that moves each bit of the count pattern one to the right (useful for various binary math operations). An interaction between the attempted reset and the count circuits, I guess (?).
Note: DicemanX's AND gate based reset mechanism functioned
Also, regarding the " * " in the top of the post: some logic gate latch types work with Terraria wiring, while others seem to fail in certain configuration. This "gated SR latch" seems to function ok:
It transfers the logic level presented at the top or bottom inputs to the opposite position output, only when the middle switch (gate) is set to enabled.
But others I failed to make function correctly, with smoke emanating from gates due to the loop back of outputs to inputs. (Maybe I was being dumb though.)
Last edited: