Niranufoti
Plantera
Serializing data for compact transmission
Table of Contents
Introduction
Ladies and gents, today I decided to get off my lazy
and actually build something I had in mind.
Imagine this: You have a password-protected door or whatever, and in order to prevent smart people with a mechanical lens and binoculars from seeing the correct solution, you have the actual logic somewhere far away, deep within your impenetrable control center. Problem: You have multiple of these doors, and each has a rather long password, leading a tangled mass of 25+ wires into your base that even you can't sort through anymore. If only there was a way to reduce the number of wires needed...
Oh wait, there is: Actual computers send masses of data through a single wire one bit after the other - can we recreate that in Terraria? Spoiler alert: I already did.
I call this "serialization" - the process of putting data in a line to be sent in an orderly fashion. Since we don't have high current and low current in Terraria and I didn't want to do timing-based stuff on the receiving end, I used two wires instead of one - but these two wires can be used to transmit (theoretically) any amount of data.
The Transistor
The core element of this is what I call the "transistor". In electronics, a transistor is a component where a so-called controlled current can only flow if there is a sufficient controlling current.
In Terraria, the transistor works based on the Faulty Logic Gate Lamp. As I outlined previously in the Official Introduction to Wiring thread (and afterwards checked in the decompiled source code), they work like this:
To stay with the electronics terminology, I'll call the faulty lamp "emitter", the regular lamp "base" and the gate "collector". If the base is active, all signals sent to the emitter will be relayed to the collector. If the base is inactive, none will.
The great advantage of this is that it allows us to check the state of something without changing anything - assuming the state we want to check is tied to the transistor's base.
In order to simplify the terminology, I'll call a transistor active if its base is active. I might also call the collector "output" and the emitter "input".
The Telegraph
The perhaps easiest application for serializing data is to simply get data from one place to another, so I built a basic four-bit telegraph: Players can input a combination on the transmitting end, flick a switch and it is copied to the receiving end.
As stated above, I used two wires to connect the two sides. I could've gone with using one of them for 1 and one for 0, but instead went with an approach that's easier to construct: One of the two wires (green in this example) tells the receiver to move to the next bit, the other one (yellow) to switch the current bit on (or off, theoretically). Also, an additional pulse on the green wire is added at the end to trigger potential feedback (e.g. opening a password-protected door).
Serializing
The serializer is rather simple - when the "transmit" switch is hit, it just needs to go through each bit, send a pulse on the green wire and then send one on the yellow wire if the bit is set. Let's take a look at it:
"Well, that's nice and orderly, but when you said 'simple', I expected the wiring to be simple, not... that D:"
I know, I know, I built it too compact for showcasing purposes, but bear with me. Let's first look at the seperate cells without caring about the wires: Each cell has red and green torches to indicate its status as well as two transistors. Initially, all cells are inactive, indicated by the red torch being active and the green torch and the transistors' bases being inactive.
Now, let's look at only the red and blue wires:
The small lump of blue wire each cell has connects the torches, bases and the switch. If this wire receives a pulse, the cell is toggled. Additionally, the collector (output) of each cell's left transistor is connected to the blue wire. If the leftmost switch is hit, the red wire, connected to the emitters (inputs) of these (left) transistors receives a pulse and all active cells are toggled, i.e. all cells are reset to their initial "off" state. The bottom blue wire, connecting the rightmost switch to the dart trap at the top, starts transmission of the stored data.
To understand how exactly the data is serialized, let's take a look at the green and yellow wires:
When the transmit switch is hit, the dart trap fires a projectile, activating the teal pressure pads in rapid succession (thanks to @AaroSA for exploring that).
The first pad of each cell, as well as the very last one, simply send a pulse through the green wire, telling the receiver to go to the next bit. The second pad of each cell sends a pulse to the right transistor. If the cell is active, this pulse continues to the yellow wire, telling the receiver to set the current bit.
Deserializing
The deserializer is a bit more complex, with more than twice as many transistors. This is the general rule - deserializing is always more difficult than serializing. But let's not be intimidated.
"You forgot the walls on the top layer. Also, the bottom corridor is useless"
Seriously? I'm presenting you with yellow notes, red zigzag, a blue and red dashed line and a green and yellow comb and you complain about that? Psh, kids these days.
On a more serious >note<, some of you will have already realized that the bottom right transistors of each cell don't do anything. Those are for state-checking, e.g. to see if the correct passcode was entered. In this basic telegraph, they don't serve any function (yet).
For more clarity, let's divide this into red, blue and yellow&green again:
The yellow "notes" act like the blue lumps in the transmitter, except this time, they're not connected to a switch, but to the collector of their cell's top-right transistor. The red zigzag line resets the cells' states, which are stored in the bottom transistors. Why is the line zigzagged? To not connect with anything else. I don't have the space to add another layer between the top and bottom part.
The top transistors handle the listening: The leftmost one and each cell's top-left one connect to the green wire coming from the transmitter. Only one of those must be active at any time. When a signal is received through the green wire, the active green-listening transistor switches its own base and that of the other (top-right, yellow-listening) transistor of its cell off and those of the next cell on. When the leftmost transistor toggles itself off, it also resets the data storage (zigzag wire). The OR-gate on the right is simply there to change the wire color from red to blue to connect back to the left.
Now, at any time, one of two things may be the case: Either the leftmost transistor is active - this means the device is ready to receive data - or a pair of top transistors of a cell is active - this means the device is currently receiving data. Whenever a green pulse is received, the active listening cell will move one cell to the right. A pulse on the yellow wire will go through the top-right transistor of the currently active listening cell, toggling the (storage) cell below. The final green pulse returns the listening focus to the leftmost listener and might be used to trigger some kind of feedback.
The Future
So there you have it - any amount of data with just two wires. This thing can be extended to... however far a dart flies, and even then, you could easily have it shoot another dart. It could probably be made quicker and some safeguards could be added to prevent a transmitter from sending more data when transmission is in progress (assuming it takes long enough to transmit that the darts can fire again), and the receiver could answer over the same wire, assuming it stops listening for a moment.
I'm thrilled to see what crazy things you guys can come up with using this - I know Iwill might use this, as it was my original plan, to solve the problem described in the introduction - a passcode-protected door that doesn't check whether the code was correct by itself, but asks the auth server.
Also, if I find the time, I might add a concrete example to this - though, if someone else builds this in a more easily understandable way and records a video, I'd thankfully include it here as well.
That said, I want to again thank @Yoraiz0r for first pushing me towards the faulty lamps, @FelixNemis for the inspiration from his RS latch and @AaroSA for showing that teal pressure pads are activated by darts just passing by. You guys rock!
Table of Contents
Introduction
Ladies and gents, today I decided to get off my lazy

Imagine this: You have a password-protected door or whatever, and in order to prevent smart people with a mechanical lens and binoculars from seeing the correct solution, you have the actual logic somewhere far away, deep within your impenetrable control center. Problem: You have multiple of these doors, and each has a rather long password, leading a tangled mass of 25+ wires into your base that even you can't sort through anymore. If only there was a way to reduce the number of wires needed...
Oh wait, there is: Actual computers send masses of data through a single wire one bit after the other - can we recreate that in Terraria? Spoiler alert: I already did.
I call this "serialization" - the process of putting data in a line to be sent in an orderly fashion. Since we don't have high current and low current in Terraria and I didn't want to do timing-based stuff on the receiving end, I used two wires instead of one - but these two wires can be used to transmit (theoretically) any amount of data.
The Transistor
The core element of this is what I call the "transistor". In electronics, a transistor is a component where a so-called controlled current can only flow if there is a sufficient controlling current.
In Terraria, the transistor works based on the Faulty Logic Gate Lamp. As I outlined previously in the Official Introduction to Wiring thread (and afterwards checked in the decompiled source code), they work like this:
An experimental application by @FelixNemis gave me the push I needed to invent this:What gate is used doesn't matter [...]; neither do lamps placed above the faulty one.
When the faulty lamp gets a signal, the gate is randomly activated with a certain chance. This chance [is] determined by the logic gate lamps below the faulty one, more specifically (number of active lamps)/(number of total lamps), e.g. if you have three active ones and one inactive one between the faulty lamp and the gate, there's a 75% chance of activation.

To stay with the electronics terminology, I'll call the faulty lamp "emitter", the regular lamp "base" and the gate "collector". If the base is active, all signals sent to the emitter will be relayed to the collector. If the base is inactive, none will.
The great advantage of this is that it allows us to check the state of something without changing anything - assuming the state we want to check is tied to the transistor's base.
In order to simplify the terminology, I'll call a transistor active if its base is active. I might also call the collector "output" and the emitter "input".
The Telegraph
The perhaps easiest application for serializing data is to simply get data from one place to another, so I built a basic four-bit telegraph: Players can input a combination on the transmitting end, flick a switch and it is copied to the receiving end.
As stated above, I used two wires to connect the two sides. I could've gone with using one of them for 1 and one for 0, but instead went with an approach that's easier to construct: One of the two wires (green in this example) tells the receiver to move to the next bit, the other one (yellow) to switch the current bit on (or off, theoretically). Also, an additional pulse on the green wire is added at the end to trigger potential feedback (e.g. opening a password-protected door).
Serializing
The serializer is rather simple - when the "transmit" switch is hit, it just needs to go through each bit, send a pulse on the green wire and then send one on the yellow wire if the bit is set. Let's take a look at it:


"Well, that's nice and orderly, but when you said 'simple', I expected the wiring to be simple, not... that D:"
I know, I know, I built it too compact for showcasing purposes, but bear with me. Let's first look at the seperate cells without caring about the wires: Each cell has red and green torches to indicate its status as well as two transistors. Initially, all cells are inactive, indicated by the red torch being active and the green torch and the transistors' bases being inactive.
Now, let's look at only the red and blue wires:


The small lump of blue wire each cell has connects the torches, bases and the switch. If this wire receives a pulse, the cell is toggled. Additionally, the collector (output) of each cell's left transistor is connected to the blue wire. If the leftmost switch is hit, the red wire, connected to the emitters (inputs) of these (left) transistors receives a pulse and all active cells are toggled, i.e. all cells are reset to their initial "off" state. The bottom blue wire, connecting the rightmost switch to the dart trap at the top, starts transmission of the stored data.
To understand how exactly the data is serialized, let's take a look at the green and yellow wires:

When the transmit switch is hit, the dart trap fires a projectile, activating the teal pressure pads in rapid succession (thanks to @AaroSA for exploring that).
The first pad of each cell, as well as the very last one, simply send a pulse through the green wire, telling the receiver to go to the next bit. The second pad of each cell sends a pulse to the right transistor. If the cell is active, this pulse continues to the yellow wire, telling the receiver to set the current bit.
Deserializing
The deserializer is a bit more complex, with more than twice as many transistors. This is the general rule - deserializing is always more difficult than serializing. But let's not be intimidated.


"You forgot the walls on the top layer. Also, the bottom corridor is useless"
Seriously? I'm presenting you with yellow notes, red zigzag, a blue and red dashed line and a green and yellow comb and you complain about that? Psh, kids these days.
On a more serious >note<, some of you will have already realized that the bottom right transistors of each cell don't do anything. Those are for state-checking, e.g. to see if the correct passcode was entered. In this basic telegraph, they don't serve any function (yet).
For more clarity, let's divide this into red, blue and yellow&green again:



The yellow "notes" act like the blue lumps in the transmitter, except this time, they're not connected to a switch, but to the collector of their cell's top-right transistor. The red zigzag line resets the cells' states, which are stored in the bottom transistors. Why is the line zigzagged? To not connect with anything else. I don't have the space to add another layer between the top and bottom part.
The top transistors handle the listening: The leftmost one and each cell's top-left one connect to the green wire coming from the transmitter. Only one of those must be active at any time. When a signal is received through the green wire, the active green-listening transistor switches its own base and that of the other (top-right, yellow-listening) transistor of its cell off and those of the next cell on. When the leftmost transistor toggles itself off, it also resets the data storage (zigzag wire). The OR-gate on the right is simply there to change the wire color from red to blue to connect back to the left.
Now, at any time, one of two things may be the case: Either the leftmost transistor is active - this means the device is ready to receive data - or a pair of top transistors of a cell is active - this means the device is currently receiving data. Whenever a green pulse is received, the active listening cell will move one cell to the right. A pulse on the yellow wire will go through the top-right transistor of the currently active listening cell, toggling the (storage) cell below. The final green pulse returns the listening focus to the leftmost listener and might be used to trigger some kind of feedback.
The Future
So there you have it - any amount of data with just two wires. This thing can be extended to... however far a dart flies, and even then, you could easily have it shoot another dart. It could probably be made quicker and some safeguards could be added to prevent a transmitter from sending more data when transmission is in progress (assuming it takes long enough to transmit that the darts can fire again), and the receiver could answer over the same wire, assuming it stops listening for a moment.
I'm thrilled to see what crazy things you guys can come up with using this - I know I
Also, if I find the time, I might add a concrete example to this - though, if someone else builds this in a more easily understandable way and records a video, I'd thankfully include it here as well.
That said, I want to again thank @Yoraiz0r for first pushing me towards the faulty lamps, @FelixNemis for the inspiration from his RS latch and @AaroSA for showing that teal pressure pads are activated by darts just passing by. You guys rock!
Last edited: