1. We have hub threads for known bugs/issues and statuses of fixes for Mobile, 3DS, and Console platforms (UPDATED):
    Click here for Mobile
    Click here for 3DS
    Click here for PS3/PS4/PS Vita/XBox 360/XBox One

An Official Introduction to Terrarian 1.3.1 Wiring & Mechanics

Discussion in 'PC - Re-Logic' started by Yoraiz0r, Apr 26, 2016.

  1. Yoraiz0r

    Yoraiz0r Lead Developer Re-Logic

    [​IMG]


    Introduction - Wiring in Terraria
    Hello everyone!

    I wrote this thread with the purpose of giving everyone an approachable starter guide centered around wiring in Terraria. I hope you will enjoy reading through it and that it will open your eyes to the possibilities that wiring in Terraria provides!

    Terraria is a game with 3 primary goals: Dig, Fight, Build!

    The focus of this thread is to give you some guidance on building - more specifically, the wiring and mechanical side of building in Terraria. Wiring in Terraria refers to using certain triggers, wires and devices to build automated or advanced contraptions to accomplish a wide array of tasks and functions. Using the Terraria wiring system, you can do many things such as, but not limited to:
    • Using automatic doors that only open or close for players
    • Placing street lights that only turn on at night
    • Defending your home from monsters with a variety of traps
    • Advanced machines limited only by your imagination - from animated fountains to player accelerators to digital displays and much, much more!
    The list could go on and on - the possibilities are endless - so without further delay, let's begin your journey to understanding wiring in Terraria!

    top
    [​IMG]

    Start Here First: Prerequisites to wiring

    So, as with most things in Terraria, you have to explore your world in order to gain access to wiring. Not sure where to go? No worries, just follow the steps below and you will be ready to start building clever Terrarian machines in no time! In order to begin wiring in Terraria, you will need to...
    • Go to a certain ominous place at night
    • Defeat the evil guardian blocking its entrance
    • Wander around inside, until you find this fair maiden
    • Save her, so she can sell you her quite reasonably priced tools required to place and remove wires - a critical component to building machines in Terraria!
    • It is probably wise at this point to build a room for her in your establishment so she that may live in a place that is easy to access
    • Once you have completed the adventure outlined above, you will then be ready to begin freely exploring messing all that wiring in Terraria has to offer!

    top
    [​IMG]

    Back to Basics: Tools, Triggers, Devices, and Traps
    After you've met the requirements necessary to unlock the wiring tools, it's time to dive in and learn more about what is possible and how it all works!


    The Basic Workflow of Wiring
    Setting up a simple wired machine in Terraria is really quite easy. Once you have the necessary Tools, a Trigger, and a Device you simply follow the three steps below to get everything hooked up:

    1. Place the device you want to manipulate
    2. Place a trigger which will manipulate it
    3. Connect the two with wire
    After the mechanic has settled in her room in your home base, she will offer a variety of items for you to purchase. These items are split to three categories: tools, triggers, and devices - let's will go through each of them individually to explore how they work.
    Note: The list isn't full - just introductory - You can also find or craft some of these, not everything is store-bought!


    [​IMG]

    Tools

    The Tools category covers the items and supplies that you will need to lay wires to connect all of your machinery together.
    • [​IMG] Wires - these are supplies used for wiring, they can only be placed with a wrench.
    • [​IMG] Wrenches - these come in four colors, placing wire that matches their color as you use them.
    • [​IMG] Wire Cutter - this tool removes wires you previously placed, letting you pick it up and place it in a different spot or as a different color.
    • [​IMG] Junction Box - these are placeable, and they prevent wires of the same color from intersecting. You can also hammer these into different shapes.

    [​IMG]
    Triggers
    Items you find in this category are always placeable, and are able for you to interact with in a certain way. When used, they will affect all devices connected to them with wire. The form of interaction changes between each of them, and the act of interaction is referred to as triggering - hence the name Triggers.
    • [​IMG] Pressure Plates - these trigger whenever stepped on by a player or an NPC.
    • [​IMG] Timers - these trigger each X seconds, X being the number shown on them; they can also be turned on/off via direct interaction.
    • [​IMG] Switches / Levers - these only trigger when directly interacted with. (with exception to Detonators, which can be jumped on to trigger)

    [​IMG]

    Devices

    Items you find in this category are always placeable, and when affected by wire (via a Trigger) their function will be activated.
    • [​IMG] Light Sources - when activated they turn on/off.
    • [​IMG] Music Boxes - when activated they play/stop their music.
    • [​IMG] Doors - when activated they open/close.
    • [​IMG] Statues - when activated they may spawn what they look like!
    • [​IMG] Inlet/Outlet Pumps - if an inlet & an outlet are activated by the same wire color, liquid will move from the inlet to the outlet.
    • [​IMG] Actuators - these are placed over common blocks, when activated they "Actuate/Deactuate" their block, letting you pass through it.
    There are many other Devices for you to discover in Terraria! Some of our favorites include: Water Fountains, Teleporters, Fireworks!

    [​IMG]
    Traps

    Items you find in this category are devices often found while exploring the world that can harm you and NPCs alike. To avoid ruining the surprise for newcomers to Terraria - this section only lists one of the more commonly-encountered traps, but these instructions will work for any trap!
    • Traps work exactly like other Devices - requiring a Trigger and a wired connection to set them off.
    • Many of the traps in Terraria may be rotated when hit with a hammer.
    • After activation, there is a delay until it can be activated further - usually lasts 1~3 seconds.
    The [​IMG] Dart Trap - most commonly found underground, shoots a poison dart at the direction it is facing whenever activated, for example.


    [​IMG]
    Giving it a Try: Some Basic Wiring Examples

    EXAMPLE #1: Automatic Door

    After knowing what tools, triggers, and devices you have, you can now put them to work! Following The Basic Workflow, let's make an automatic door!

    The steps to making this clever time-saving machine are quite simple, let's see...
    1. Place the device - in this case a [​IMG]Wood Door
    2. Place a trigger - in this case a [​IMG]Pressure Plate
    3. Connect the two with [​IMG]Wire
    4. Voila! You are the proud owner of one Automatic Door!
    Here's a slow-mo of these steps in action
    [​IMG]
    [​IMG]
    EXAMPLE #2: Automated Defenses
    After making a simple automatic door, you can probably tackle something more advanced, such as an automatic defense for your home. Following The Basic Workflow again, we can wire up a defensive trap like so...
    1. Place the device - in this case a [​IMG]Dart Trap
    2. Place a trigger - in this case we will use a [​IMG]Switch / Lever and a [​IMG] Timer.
    3. Connect the three with [​IMG]Wire
    Here's a slow-mo of these steps in action
    [​IMG]
    [​IMG]
    EXAMPLE #3: Simple Toggled Lights
    For convenience, one common use of wires is toggled lights for your base, let's try that out.
    Following The Basic Workflow once more, we can wire up a light fairly easily.
    1. Place the device - in this case a [​IMG] Torch
    2. Place a trigger - in this case we will use a [​IMG]Switch / Lever.
    3. Connect the two with [​IMG]Wire
    Here's a slow-mo of these steps in action
    [​IMG]

    top
    [​IMG]

    Taking it to the Next Level: New & Advanced Triggers - Sensors & Logic Gates

    In the previous section we covered all the basic usage elements of wires, most of which were already available in Terraria for years. However, the 1.3.1 Update brings with it a fresh set of possibilities via all new Trigger types! Now that you understand the basic elements of Wiring, we can learn to use more these advanced triggers - such as Sensors & Logic Gates.

    Sensors
    The 1.3.1 Update has added Sensors - These fit into the Trigger category, as they trigger based on a specified condition.
    • [​IMG] Logic Sensor (Day) - these only trigger once an in-game day starts, at 4:30AM.
    • [​IMG] Logic Sensor (Night) - these only trigger once an in-game night starts, at 7:30PM.
    • [​IMG] Logic Sensor (Player Above) - these trigger On Condition Change, the condition being "there is at least one player over the sensor".
    I'd like to emphasize that [​IMG] Logic Sensor (Player Above) can trigger from two cases - both when a player enters its detection range AND when leaving that range.

    [​IMG]
    Logic Gates
    Prior to the 1.3.1 Update, complex machines in Terraria required quite massive structures in order to perform the Logic functions central to their operation. This update greatly simplifies that process and makes it so much more accessible: without further ado, I give you... Logic Gates.
    [​IMG] [​IMG] [​IMG] [​IMG] [​IMG] [​IMG]

    To understand how Logic Gates work, you need to have a good understanding of "binary". Binary is an adjective that means "having only two states" (ON / OFF, for example) and is critical to all modern computing devices.

    Logic gates are devices that take multiple binary inputs & compare them against a condition. For example, this [​IMG] Logic Gate (AND) compares to the condition "this AND that are ON.".

    So how do you feed input into logic gates? by using [​IMG] Logic Gate Lamps.
    [​IMG] Logic Gate Lamps are devices that have an ON/OFF state, can only be placed above gates or other lamps & on activation they toggle their state.

    Lastly, let's look into the gates themselves.
    Logic gates - these fit into the Trigger category, as they trigger based on their conditional state's changes.
    • [​IMG] Logic Gate ( AND ) - triggers on condition change - the condition is "All inputs are ON"
    • [​IMG] Logic Gate (NAND) - triggers on condition change - the condition is "NOT all inputs are ON"
    • [​IMG] Logic Gate ( OR ) - triggers on condition change - the condition is "At least one input is ON"
    • [​IMG] Logic Gate ( NOR ) - triggers on condition change - the condition is "NOT even one input is ON"
    • [​IMG] Logic Gate ( XOR ) - triggers on condition change - the condition is "Only one input is ON"
    • [​IMG] Logic Gate (NXOR) - triggers on condition change - the condition is "Total ON inputs count is NOT 1"

    [​IMG]
    The Gated Workflow
    It is important to note that if you intend to use logic gates, your basic workflow changes.
    1. Place the device you want to manipulate
    2. Place the Logic Gate of the condition you wish to check & the required amount of logic gate lamps for it
    3. Place at least one additonal trigger per Logic Gate Lamp
    4. Connect the Logic Gate to the device with wire
    5. Connect each Logic Gate Lamp to a trigger using wires of different colors
    Confused? Don't be! Let's look at a few examples to help it all come together and make sense.

    [​IMG]
    Putting Binary to Work: Logic Gate Examples

    EXAMPLE USAGE #1 - AND Gate

    Following The Gated Workflow, let's make a "secret passage" that opens up if you flip two levers on. This is actually pretty simple, check it out...
    1. Place the device - in this case a few [​IMG]Actuators
    2. Place logic gate and lamps - in this case an [​IMG]AND Gate & two [​IMG]Logic Gate Lamps
    3. Place triggers for each lamp, in this case two [​IMG]Switches / Levers
    4. Connect the logic gate to the actuators with [​IMG]Wire.
    5. Connect each logic gate lamp to a lever with differently colored [​IMG]Wire.
    Here's a slow-mo of these steps in action
    [​IMG]
    [​IMG]
    EXAMPLE USAGE #2 - OR Gate
    Often when making games or adventure maps, there's a need to create conditions that can only be toggled in one direction, such as "finished a quest" or "solved this puzzle".
    Following The Gated Workflow, we can make a gate that can only turn on once and then stay on forever, let's do that!
    1. Place the device - in this case a [​IMG] Door will be good.
    2. Place logic gate and lamps - in this case an [​IMG] OR Gate & two [​IMG]Logic Gate Lamps
    3. Place triggers for each lamp, in this case we only need one [​IMG]Switch / Lever, as the gate would connect itself to the other lamp!
    4. Connect the logic gate to the door & one of the logic lamps with [​IMG]Wire.
    5. Connect the other logic gate lamp to a lever with differently colored [​IMG]Wire.
    Here's a slow-mo of these steps in action
    [​IMG]
    The result is that the door will open once and stay opened forever after 1 flick of the lever, because the conditions for it to remain open are "flicked the lever OR did the gate activate at least once" - which happens thanks to the lever flick!​
    [​IMG]
    EXAMPLE USAGE #3 - XOR Gate
    There's some situations where you'd like to detect if a choice has been made out of multiple ones, and if so - which choice?
    For example, of choosing between GOOD or EVIL, you want to give someone the choice and not let them proceed until they've picked their side.
    Following The Gated Workflow, it can be done using XOR gate with any number of choices you'd like.
    1. Place the device - once again a [​IMG] Door. (and some torches for visual feedback)
    2. Place logic gate and lamps - in this case an [​IMG] XOR Gate & two [​IMG]Logic Gate Lamps
    3. Place triggers for each lamp, two [​IMG]Switches / Levers.
    4. Connect the logic gate to the door with [​IMG]Wire.
    5. Connect the each logic gate lamp to a lever with differently colored [​IMG]Wire, and place a torch on the path of each wire color.
    Here's a slow-mo of these steps in action
    [​IMG]
    top
    [​IMG]
     
    Last edited by a moderator: May 22, 2016
    Koala, OddGirl, ppowersteef and 49 others like this.
  2. Gigavoir

    Gigavoir Spazmatism

    I'll have to get back in to map making with all of this. Looking great!
     
    Jabelspector likes this.
  3. KinfPL

    KinfPL Terrarian

    Brain blown by the simplest mechanics that terraria didn't have, now i need to find the mechanic... Skeletron, here i come!
     
  4. Jofairden

    Jofairden Retinazer

    Nice, this should help people a lot ;)
     
  5. teag2

    teag2 Skeletron Prime

    Awesome! Can't wait to play this later.
     
    Liquid_ph34r likes this.
  6. Niranufoti

    Niranufoti Skeletron Prime

    So wait, the polyadic (multary) XOR gate isn't actually an XOR gate, but a one-hot detector? To get an actual polyadic XOR, we have to build our own diode?
     
    Last edited: May 22, 2016
    Noit likes this.
  7. Reactorcore

    Reactorcore Terrarian

    I learned a lot from this guide, thank you! :)

    For those who have unstable or no internet, could this be included with the game as a pdf in the installation folder?
    You know, for official reference, since there are no tutorials or otherwise available to learn this within the game itself.
     
    OneEyedWolf likes this.
  8. Unit One

    Unit One Moderator Staff Member Moderator

    This is a fantastic guide, thank you for putting it together for us. It is clear and thorough and took a great deal of time and effort. I appreciate it.
     
  9. DicemanX

    DicemanX Brain of Cthulhu

    Excellent guide @Yoraiz0r! I was just curious - would you consider posting a duplicate thread in the T-MEC forums so we can sticky it? I imagine that the info will be useful for a long time to come. We could also just link this thread of course, but it's easier to have the visuals and text in the post itself.

    Fine work on the logic gates as well. Prior to 1.3.1 we needed to use separate reset systems to revert the outputs back to their original states before sending signals through the gate again (to prevent the gates from working as mere toggles), but the 1.3.1 gates have a really elegant "reset" by sending a pulse when the logic gate square boxes turn off or turn on.

    I was nevertheless curious - did you have something specific in mind when designing the N versions of the gates? Since the outputs are arbitrarily determined in a pulse-based system, it is possible to switch over from, say, an AND gate to a NAND gate merely by changing the definitions of the outputs or by reversing their state (switching a off torch to the on state, actuating or deactuating a block, opening or closing a door etc.). Did you foresee a situation where a NAND gate would need to be used over an AND gate? If not, I suppose the AND and NAND versions are still a good idea if one wanted to build Terraria electronics more faithful to real world electronics systems :).
     
  10. FakeInferno

    FakeInferno Steampunker

    The ideas are arising! Can't wait to try them out!
     
  11. Niranufoti

    Niranufoti Skeletron Prime

    I obviously can't know what the team had in mind doing this, but you have to remember that not everyone gets all of this stuff as easily as people like you and me. I'd assume that most of these are mainly there so things are easier to understand - technically, A & B is equivalent to !(!A | !B), so we'd have only needed one of AND, NAND, OR and NOR. Also, a real XOR gate (addition modulo 2) in a pulse-based system would be the same as a diode with multiple inputs (I'm pretty sure I mentioned that before somewhere), and since a diode could be easily made with any logic gate and just a single logic gate lamp (with at least up to three inputs; haven't checked how exactly the junction thingies work), you could theoretically build all the logic gates using only one of them.
    But most people would be intimidated by it if it was that complicated and might not even try understanding it - we wouldn't want that, would we now?
     
  12. Yoraiz0r

    Yoraiz0r Lead Developer Re-Logic

    Terraria logic gates let you place as many lamps as you want on them, a XOR gate activates when only 1 lamp is 'on', from all the lamps, I'm uncertain as to what the difference is between a "polyadic XOR" & a "3+ lamps one-hot detector", you'd have to be more specific o_O


    For moving/duping the thread - looking into it.

    As for designing the N versions - I put more thought into the usability of the logic gates than which gates to add, the N versions are just there for those who want to keep a clear vision of why they use which gate and where.
    It is easier to know that you want a NAND or a NOR if they're just red colored and waiting for you rather than trying to remember the purpose of each gate in the long run, clarity's important after all.
     
    ZeroGravitas and Leinfors like this.
  13. Dark_Reaper115

    Dark_Reaper115 Terrarian

    FINALLY !!! After all this years my one request is part of the game !!! We have diodes so actually make circuits !!!
    I guess im not the only one doing a "mechanic" playthrough... I might add some technological weapons/guns or just be a summoner. After all, if you want machines to do your work, might as well also leave minions do your work.
     
  14. inomanoms

    inomanoms Eye of Cthulhu

    How do I recognize which gate is which from their colour coding?
     
  15. Niranufoti

    Niranufoti Skeletron Prime

    According to my sources (i.e. Wikipedia and common sense), polyadic XOR would be "addition modulo 2", that is, the output is 1 if an odd number of inputs is 1. That's what you get when evaluating a chain of A XOR B XOR C XOR ... XOR N in any order. Of course it's useful to have a =1 gate, since as I outlined previously, unless an even number of inputs of the XOR (addition modulo 2) gate are toggled (receive a pulse) at the same time, any change in input causes a change in output (a pulse), so in Terraria's pulse-based system, it's effectively the same as a diode. Still, maybe it shouldn't be called an XOR gate, and the XOR gate should be implemented seperately (if at all).
    Also, while we're at suggesting new gates, an "any but not all" gate would be nice as well. Then we'd have three gates that would work the same with two inputs, but work differently at higher levels.
    Though, then again, anything other than the current "=1" XOR gate could be constructed rather easily.
     
    ZeroGravitas and Yoraiz0r like this.
  16. yugiohhero

    yugiohhero Brain of Cthulhu

    Im confused what does logic have to do with robotics?
     
  17. Noit

    Noit Terrarian

    He means the equivalent of having 2+ inputs for a single gate, "should" be the same as putting multiple 2 input ones in association. For example A AND B AND C is the same as (A AND B) AND C. So A XOR B XOR C should be the same as (A XOR B) XOR C, in your implementation it isn't, for example 1 XOR 1 XOR 1 is 0, but (1 XOR 1) XOR 1 is 1. In order to be like that it should be "An odd number of inputs are ON", and for the XNOR "Not an odd number of inputs are ON" which is the same as "An even number of inputs are ON". This is how is commonly interpreted:
     
  18. DragonOmnus

    DragonOmnus Terrarian

    If I'm not mistaken, isn't that the NAND gate?
     
  19. TheComputerCrasher

    TheComputerCrasher Terrarian

    Wait a minute. I thought Terraria had 4 primary goals: Dig, Fight, EXPLORE, Build!
     
    Gigavoir likes this.
  20. DicemanX

    DicemanX Brain of Cthulhu

    This was possible to construct in pre-1.3.1 by connecting any number of switches/pressure plates to a wire connected to an output :). So long as there are an odd number of inputs the output is always 1. We now have a dedicated gate for this function, but it might be easier to just use the previous approach.


    Yes indeed, it's probably going to be easier for many have all 6 gates at their disposal instead of just relying on 2. In my demonstration videos I'll most likely use the other gates as well even though I really only need the AND gate.