1. For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
    Dismiss Notice
  2. For issues you find with the Mobile 1.3 update, please follow this link and give as much detail as possible. This is the speediest way to get info to DR Studios to look at your issue. Also, some troubleshooting hints here.
    Dismiss Notice
  1. Programmatic

    Programmatic Steampunker

    So it's been a while since a made a post on this forum. I've been busy lately, and I haven't been able to complete any large projects recently. So, until I come up with something big to make, I decided I would try something new. I'm going to create a tutorial, but instead of just one big guide on wiring, I'm going to post a small tip on wiring every day. This way, I hope to progressively go from the very basics of wiring and logic gates to the more complex devices. I've seen a lot of new users joining T-MEC lately, so this tutorial will be a fun little project to help you beginners master wiring at a comfortable pace.

    So without further ado, let's get on with the first tip!

    Tip #1: Use TEdit

    I know a lot of wiring beginners may not be willing to work with third party tools, but TEdit is beyond helpful. Working with wiring in Terraria is a very fragile process. Nothing is more frustrating than starting to build something big, only to find that there's not enough room to build it in the space you set up. In Terraria, you would have to destroy your entire creation just to rebuild it somewhere else, but with TEdit, you can simply move the whole thing. With TEdit, you also have access to undo, redo, copy, and paste, four absolutely essential functions. Many devices that you make will consist of a few small components duplicated multiple times. Building each piece in Terraria can be tedious, but with TEdit, you can copy and paste something dozens or even hundreds of times in just a few clicks. Using TEdit also allows you to eliminate one of the biggest obstacles to wiring: the world. All you need to do is generate a largge, blank world and bucket fill it with diamond gemspark walls, which will illuminate everything without the need of torches. There are many other advantages that TEdit has over regular building in Terraria, and I highly suggest that you learn to use it. Just make sure that you always backup your worlds and use the most up-to-date version of TEdit.

    That's all for today. Tomorrow, I'm going to talk about faulty lamp gates. Until then, feel free to post whatever questions, comments, or suggestions you may have.
    Good luck! :happy:
    Zer0vs, Tyro, inomanoms and 5 others like this.
  2. shobiwan77

    shobiwan77 King Slime

    This is a great idea. I know how to use logic gates to a reasonable level, but it doesn't come close to what you and many other T-MEC users can do. This is a great way to learn without watching a couple hours of YouTube videos.

    On topic of your first day post, I feel like this is a very important point to start out with. TEdit is definitely a must have for mass scale wiring in Terraria. Good starting post, and I look forward to seeing more.
  3. definitely gonna keep posted on this
    tip #1 already seems like it's very logical
  4. Programmatic

    Programmatic Steampunker

    As requested by Tang3nt, I've moved day 2 to this thread. I'll post the next 5 tips on this thread and then make a new thread next week so that this one doesn't get too big.

    Tip #2: Use the faulty logic lamp to make flip-flops

    While there are various logic gates that can be used to perform the fundamental logical operations such as AND, OR, and XOR, there is another logic device that some beginners may overlook or underestimate: the faulty logic lamp. The function of the lamp is fairly simple; attaching the lamp to the top of any logic gate will change its function, causing pulses that are sent to the faulty lamp gate to have a certain probability of coming out the bottom of the gate, based on what percentage of the intermediate logic lamps are active. When only one logic lamp is inserted, the gate will always either allow or deny pulses that travel through it.
    Because of this function, the faulty lamp gate (as I will call it from now on) acts as a transistor that can be used to control the flow of signals. Yet, the faulty lamp gate can be used for more than simple transistors; it can also be used to create flip-flops. A flip-flop is a logic device that is able to store a value. Different types of flip-flops behave differently based on the inputs they receive. The first flip-flop that I will show you is the D (for "data") flip-flop:


    The D flip-flop holds a specific value and has two inputs; the first input (red) is a trigger that sets the flip-flop's stored value (green) to the current value of the second input (blue). With this, you can easily store information for later use. This flip-flop works due to the logic lamp's ability to function as a XOR gate; when two inputs are connected to the same logic lamp, the lamp turns on only when the inputs' values are different. Here, both the input and output wire are connected to the logic lamp. Triggering the flip-flop when these values are different causes the output's value to change and match the input's value.
    The D flip-flop is also easily tileable, making it useful for storing large amounts of information with a single trigger:


    That's all for today. Tomorrow, I'm going to talk about SR latches. Until then, feel free to post whatever questions, comments, or suggestions you may have.
    Good luck! :happy:
    --- Double Post Merged, Feb 19, 2017, Original Post Date: Feb 18, 2017 ---
    Tip #3: Use faulty lamp gates to make SR latches

    In addition to the D flip-flop, another useful flip-flop is the SR (for "set, reset") latch:

    [​IMG] [​IMG]

    The SR latch functions similarly to the D flip-flop, but instead of having one trigger and one value input, it has two trigger inputs. One trigger (blue) turns the latch on, while the other (red) turns it off. This can be useful for making devices that can't be turned off after they are activated, except with a reset switch.
    Like the D flip-flop, the SR latch is also easily tileable, allowing you to connect one reset switch to multiple latches:


    That's all for today. Tomorrow, I'm going to talk about binary code. Until then, feel free to post whatever questions, comments, or suggestions you may have.
    Good luck! :happy:
    Also, I've attached the world file for those of you who would like to test / experiment with the devices yourselves. It's a very small file, but be sure to delete it if you download later versions of it:
    --- Double Post Merged, Feb 20, 2017 ---
    Tip #4: Learn binary

    In electronics, it is impossible for computers to do calculations using the number system that we are all familiar with: the decimal system. Instead, digital devices use a number system known as binary. Unlike decimal, which uses 10 unique digits (0 through 9), binary only uses 2 (0 and 1). This is because electronic signals can only have two different states, off and on, which correspond to 0 and 1. Seeing long strings of 0s and 1s can be intimidating, and it may seem hard to figure just how to do math with only two digits, but in reality, binary works exactly the same as decimal.
    Consider the "expanded form" of decimal numbers. In expanded form, each digit of a number is written as that digit multiplied by a power of 10. For example, 12345 = 1*10000 + 2*1000 + 3*100 + 2*10 + 1*1. Binary works the same, but instead of using powers of 10, it uses powers of 2. For example, 11001 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1. If you were to consider the rightmost digit of a binary number the "0th" digit, then, from right to left, the decimal number that corresponds with each binary digit would equal 2 to the nth power.
    Manually converting a binary number to decimal is as simple as adding together the powers of 2 that correspond with each 1 in the binary number (11001, for example, is 1 + 8 + 16 = 25). Another way to convert binary to decimal is to start with 0 and then read the binary number from left to right, add 1 to your total for each 1 in the number and then doubling your number after each step except for the last step (1, 2, 3, 6, 12, 24, 25).
    Conversely, converting a decimal to binary can be done by determining which powers of 2 can add up to that number. To convert 25 back to binary, you would first find that largest power of 2 that is less than 25, which is 16. Then, subtract 16 from 25 to get 9, and then repeat this process until you reach 0. Finally, take each power of 2 that you subtracted to create a binary number.
    These techniques I've described are only ways to convert between decimal and binary manually. Doing these conversions in a computer is much more complicated, so I will leave that process for a future tutorial. I will also show how to do operations such as addition and multiplication later in the series.

    That's all for today. Tomorrow, I'm going to talk about bit shifters. Until then, feel free to post whatever questions, comments, or suggestions you may have.
    Good luck! :happy:

    Attached Files:

    Zer0vs, inomanoms, dustyfox and 2 others like this.
  5. shobiwan77

    shobiwan77 King Slime

    Tip #2 is a useful mechanism, to flip the state of something only if it was changed.

    Also, I'm surprised you've been able to keep up with writing a tip a day. Hopefully it will continue
  6. Programmatic

    Programmatic Steampunker

    Tip #5: Use faulty lamp gates to make bit shifts

    In binary, a bit shift is a function that causes every bit in a group of bits to shift to the left or right. For example, left shifting 00011001 would result in 00110010. Notice that I am adding extra 0s to the left of each number. This is because the result of a bit shift can change depending on the number of bits available, and, in this case, I will be using 8 bits (also known as a byte) for the following examples.
    If a 1 "falls off" either side of the byte when it is shifted, it is discarded.
    Mathematically, left shifting a binary number, provided that no 1s are lost, causes the number to be multiplied by 2. Right shifting a number divides it by 2, and if the number has a 1 on the right side (in which case the number would be odd), the 1 is discarded and the result is rounded down, so 00000101 (5) right shifted is 00000010 (2).
    Here is an example of a left shift:


    When the trigger (red) is activated, each faulty lamp gate that is enabled turns itself off and simultaneously turns on the lamp on its left. To create a right shift, simply mirror the design.
    By connecting the leftmost bit back to the rightmost bit, 1s that fall off the left side, instead of disappearing, are sent back to the right side of the byte. This is known as a circular left shift:


    Again, the design can be mirrored to create a circular right shift.

    That's all for today. Tomorrow, I'm going to talk about accumulators. Until then, feel free to post whatever questions, comments, or suggestions you may have.
    Good luck! :happy:
    Also, I've attached the world file for those of you who would like to test / experiment with the devices yourselves:
    --- Double Post Merged, Feb 21, 2017, Original Post Date: Feb 21, 2017 ---
    I'm glad your enjoying it. I'm hoping to continue the project for at least two weeks, but it could be shorter or longer depending on when I start running out of ideas.
    --- Double Post Merged, Feb 23, 2017 ---
    I was feeling sick yesterday, so I didn't get a chance to post another tip. I might make up for it by posting two tips sometime later in the series.

    Tip #6: Use accumulators to create adders and counters

    An accumulator is an extremely useful device that stores the sum of whatever is inserted into it. Creating an accumulator starts with a rising edge detector:

    [​IMG] [​IMG]

    The rising edge detector is a device that outputs a pulse whenever its input changes from off to on. You can also invert the logic lamp to create a falling edge detector, which only outputs a pulse when its input changes from on to off. If you place a series of falling edge detectors side by side and connected them from right to left, you would get an accumulator:


    When a wire is triggered, the stored value increases by the power-of-2 value of the corresponding bit. You can use the accumulator as a counter simply by connecting the rightmost wire to a trigger. You can also trigger multiple wires simultaneously to increment the accumulator by any value. Note that, if the value within the accumulator exceeds 11111111 (the maximum value) an overflow will occur, causing it to drop down to a lower number. By inverting all of the logic lamps (thereby turning them into rising edge detectors), you can reverse the accumulator, causing data inserted into it to be subtracted.

    That's all for today. Tomorrow, I'm going to talk about combining different devices to make more complex devices. Until then, feel free to post whatever questions, comments, or suggestions you may have.
    Good luck! :happy:
    Also, I've attached the world file for those of you who would like to test / experiment with the devices yourselves:

    Attached Files:

    Last edited: Feb 24, 2017
    Jameelioo, dustyfox and shobiwan77 like this.
  7. fooksie

    fooksie Terrarian

    I sense a [​IMG] theme
  8. Programmatic

    Programmatic Steampunker

    Yeah. I find faulty lamp gates a lot more versatile and less susceptible to gate smoke than ordinary logic gates, so most of my creations use a lot of those.
  9. fooksie

    fooksie Terrarian

    why would a standard logic gate toggle itself?

    I find logic gates criminally underused and it'd be nice to see more applications for those. faulty gates aren't really logic gates, they're just conditional gates (aside from the random feature which is far less common)
  10. Programmatic

    Programmatic Steampunker

    The main cause of gate smoke isn't from logic gates toggling themselves, but rather receiving different inputs at different iterations during the same tick. For example, if a chain of 2 logic gates and another chain of 3 merged at a single logic gate, then that gate will receive each of its inputs during different iterations, potentially resulting in gate smoke if its result were to change twice. With very large logic devices, this problem becomes a lot more complex as different large parallel functions get mixed together. A related problem is that a logic gate will always update its value whenever it receives an input, even when you currently don't need to use its output, resulting in a loss of efficiency and even lag in larger devices. With faulty lamp gates, you have much more control as you can choose when to acquire data from them.
  11. fooksie

    fooksie Terrarian

    can you replicate the logic of logic gates with a faulty lamp, considering it overrides them? that's my point: I never see actual examples of AND, NAND, OR, NOR, XOR, or XNOR. I think it's misleading to refer to faulty gates as logic gates because they really aren't, and I think it'd be useful to show applications of logic gates

    I think after one or two examples people get the gist of a faulty gate: wire to faulty lamp to check state of (typically) a single lamp, send signal if active. most people, including myself, don't know of any tips for implementing logic gates, though, so those would be very helpful
  12. ekinator

    ekinator Eye of Cthulhu

    faulty logic gates (the one that has a single lamp below the faulty lamp) are like transistors. You CAN replicate logic gates using only faulty logic and it already has been done before.
  13. Programmatic

    Programmatic Steampunker

    It is possible to simulate logic gates by using faulty gates. AND gates can be made by placing 2 faulty gates in series, and OR gates can be made by placing them in parallel. XOR gates, being obsolete due to the pulse-based nature of Terraria's wiring system, don't need to be replicated and can be made simply by connecting 2 wires to one logic lamp. The three inverse gates (NAND, NOR, and XNOR) also don't need to be replicated since they are functionally identical to their counterparts.
    When I need to make use of the functionality of an AND or OR gate, I will use those instead of faulty gates, though I generally use faulty gates more because of their use as latches. I mostly use AND gates to create multiplexers, which are used to route an input to one of many outputs, and I use OR gates either as diodes, which allow pulses to travel in only one direction, as buffers, which delay the transmission of a pulse by one logic iteration in order to synchronize certain logic gates and prevent gate smoke, or for wire color conversions.
  14. fooksie

    fooksie Terrarian

    how would an OR gate specifically be used for this?

    also, I think it'd be far more space efficient to use n lamps and 1 logic gate for, say, AND as opposed to 3n lamps and faulty gates (+ space between them)
    --- Double Post Merged, Apr 29, 2017, Original Post Date: Apr 29, 2017 ---
    also, since everyone uses faulty lamps almost exclusively and for this one specific purpose (checking if a single lamp is on and not the random lamp feature), wouldn't it be a good idea to suggest a lamp similar to faulty lamps which checks the state of a logic gate upon receiving a signal and outputs on demand? so you have an AND gate that doesn't have to change state to be checked and emit a signal

    just asking because I don't know what t-mec's opinion would be on that, to me it seems like an obvious solution to faulty gate spam but I'm finding we don't think the same
  15. Programmatic

    Programmatic Steampunker

    Both AND and OR gates can be used for color conversions, I just personally prefer to just use OR gates for the sake of consistency. Using logic gates for normal logic operations is certainly more space efficient and should be used instead of faulty lamp gates whenever possible.
    As for your suggestion, that effect can be accomplished by connecting the output of a logic gate to the logic lamp of a faulty lamp gate, and using that faulty gate either as a transistor to output pulses, or a D flip-flop to output data. I know this doesn't eliminate the need for a faulty lamp gate in such a situation, though I also think making a new type of lamp for such a specific function wouldn't be worth the developers' time to make.
  16. fooksie

    fooksie Terrarian

    no no no

    let's say I have 3 lamps and I want to check one of them is on

    I can't do that with an OR gate to my knowledge because it only sends a signal when the state of the gate changes, which both depends on changing a lamp when I only want to check the state and also requires all lamps turning off in order to change the state of the gate to output a signal

    I don't know how else to achieve this besides three faulty gates for each lamp, which is exponentially inefficient

    if you know another way it would be helpful because using a faulty lamp for every state takes a ton of space and, again, logic gates are massively disused and I think for this very purpose: the state cannot be checked without being changed
  17. Programmatic

    Programmatic Steampunker

    If, by "checking if one of them is on," you mean testing if a particular input is active, that can be done with either an AND gate to return data or a faulty lamp gate to return a pulse. If, however, you mean that you want to check that exactly one of the three inputs is active, then you could actually use a XOR gate for that. If, in this case, you also want to know which one of those three inputs is active, you could create a basic multiplexer using three AND gates. In any of these cases, the space complexity should still be linear, not exponential.

    Finally, while you will always need to use either an AND gate or a faulty lamp gate to test the value of another gate on demand, you don't need to check the output of a gate in order to use it, as it will still output pulses that toggle that values of objects that it's connected to.
  18. fooksie

    fooksie Terrarian

    I consider going from n+1 to n*3 relatively exponential but anyway can you show me an example of checking if an OR gate with 3 lamps is active or not and outputting a signal if it is without changing the lamp states?

    picture an OR gate with 3 lamps on it. I want to send a signal through that comes out if AT LEAST one of the 3 lamps is active (OR). how do I do that? I know I can do that with 3 faulty gates, but that's 3x less efficient. that's what my suggestion was for, reducing that 3x (or 6x, or 9x, or ∞x) bigger and messier-than-necessary chain of faulty gates to do what a single logic gate should be able to do
  19. Programmatic

    Programmatic Steampunker

    You should be able to do that by connecting the output of your OR gate to the logic lamp of just one faulty lamp gate, and then connecting your signal to the faulty lamp of that gate.
  20. fooksie

    fooksie Terrarian

    can you show me a picture of what you mean so I can see exactly how it's done or exactly what's being miscommunicated because I don't see how to do this with an OR gate the way it currently functions

    edit: no, wait, I see what you're saying
    I thought logic gates only sent signals when the conditions are met, but I guess they send signals every time the state of the gate changes

    still would be nice not to have to rely on a faulty gate but I did learn something useful thanks