Flip-flop is memory element holding 1 bit of data. There are multiple types of flip-flops available. One of the simplest ones is a RS flip-flop. In this example NOR gates will be used to create it (there are also variants involving NAND gates and others as well).
- 4 logic gates (in real life flip-flops only two NOR gates would be required, however in Scrap Mechanic two AND gates need to be added in order to reroute the signal from one NOR gate to another and vice versa)
- two input devices (in this example buttons)
- Build logic gates as shown below: 2 NOR gates and 2 AND gates next.
- Connect them using Connection Tool as shown below. This way the output of one NOR gate goes back as input to the second NOR gate, while the output of the second NOR gate goes back as input to the first NOR gate. Buttons are connected as the second input to their respective NOR gates.
How it works
One of the AND gates serves as a normal output, while the other serves as reversed output (if one of them is ON the other is OFF and vice versa).
Clicking one button will set the flip-flop on, while clicking the other will turn it off. Instead of a buttons any other inputs can be used, such as sensors or other logic gates.
If you are building a flip-flop for the first time, it might be useful to start with buttons as inputs and experiment to gain a better understanding of how it works.
Flip-flop has a lot of potential uses, It is especially useful whenever you need a system that can switch between two states without direct player action.
For instance, an alarm system can be build where a trespasser is detected by a sensor, activating the alarm system and whatever devices it may include. Such a system can be later deactivated by a player using a button once a trespasser is dealt with.
Another advantage of a flip-flop, as compared to something more simple like a normal switch or a sensor set to switch mode, is that different types of inputs can be used. This goes back to the previous example, where a system could be activated by a sensor and deactivated by a button.
When a flip-flop is placed on the lift or when an input button is pressed for only a very short time, it can go into an unstable state, where it switches on and off very rapidly. To solve this problem, simply press one of the input buttons. This should bring the flip-flop back to a stable state (on or off, depending on which button is pressed).