Guide:Logic Gates

Logic gates are very useful tools in Terraria for anyone wanting to construct advanced wiring creations.

This guide assumes you already have basic knowledge of wiring.

Logic Gates basics
There are six different kinds of logic gates: AND, OR, XOR, and their inverses NAND, NOR and XNOR. Each gate only turns on when specific conditions are met, and turns off when these no longer met. The AND gate, for example, only turns on when all connected lamps are on, while the OR gate simply requires at least one of its lamps be on to turn on, and won't turn off until all connected lamps are off. X stands for "exclusive", so XOR, or "exclusive OR" only turns on when either one connected lamp is on. The "N" on the inverse gates stands for NOT. While thinking of them as the opposite of their basic gates will generally work, they specifically turn off when their would turn on and vice versa. For example, the NOR gate turns on when no lamps are on, and off when at least one lamp is on. The XNOR gate turns off when exactly 1 lamp is on, and turns on when any number of connected lamps other than 1, including 0, are lit.

AND Logic Gate
The AND Gate reacts only when all inputs are true, so it can be used, for example, to restrict access to a particular area unless a player has flipped specific switches throughout the world. It's also great for situations where more than one goal needs to be achieved before a player can proceed further.

Another use for the AND Gate is wire changing, that is the color swap of the wire. AND Gates are useful where one wire color must be used for the input, but another used for the output. A good example is a complicated teleporter hub that needs to be wired to a teleporter where other wires interfere. If you just have one input, the input value and output value will always be the same.

A third use for AND Gates is for something a player doesn't want happening before other things happen. For example, a player wouldn't want the inner door of their airlock in their underwater base to open before the water was pumped out AND the outer door was closed. Using an AND Gate, the player can wire it to only open the inner door if there isn't any water in the chamber AND the outer door is closed. This can be done using switches, but using the AND Gate, it becomes more streamlined.

A fourth use for AND gates is filtering signals from other sources. Consider a large, complicated statue farm. It would be possible to control it with a series of timers, but this becomes less useful if an engine is used to increase the trigger rate. In this case, without the use of logic gates, the options are to trigger all the statues at once with the engine, or to build an engine for each set of statues. Instead, AND gates can be employed. By sending the engine's signals through an AND gate also wired to a switch, no signals from the engine will be passed through to the statues until the switch is thrown.

XOR Logic Gate
XOR Logic Gates reacts when exactly one input is on, so they can be used for cases where you only want one active. For example in an adventure map, if you want players to only select one room, you may wire up an XOR Gate to some pressure plates so that once they enter a room, they may still backtrack to the previous room, but not to the rooms they didn't choose.

The big idea with XOR Gates is having to make a choice, while at the same time, shutting off other options once that choice has been made.

OR Logic Gate
The OR reacts when at least one input is active. It can be used when the player only has to complete one task, out of many, and you are okay with more than one being completed. One examples would be having multiple ways to open a path, in an adventure map for example. OR Gates can also be useful outside of adventure maps, for instance, if the player wants to wire an OR gate so that when day shifts to night or when an enemy comes into range of your defenses, they turn on. This would be useful for discouraging any slimes or other daytime baddies from attacking you.