Rec Room Wiki
Advertisement
Rec Room Wiki

This page contains a collection of reusable CV1 circuits that solve certain functions and can be used to create larger CV1 circuits.Circuittest

General Concepts[]

Stores[]

Ring Store[]

RingStore

We have no memory chips at the moment, but we can store values by forming a ring. The ring can be extended by more chips that modify the value. Note however, that rings larger than one chip can be affected by the Ring Evaluation Order issue, if they have more than one entry point to the ring. Ring stores should be designed in a way that they do not modify the value in the default state, only once when required (e.g. when the user presses a button). Otherwise they will continuously do so.

RNG Store[]

RngStore

A random number generator chip in continuous mode can be used to hold a single value. Compared to ring stores, RNG stores are not affected by the Ring Evaluation Order issue, but do not provide native reset capabilities. So to be able to reset the value to 0, additional chips are required.

Single Bit Store[]

See RS Latch.

Increment[]

Increment

This circuit increments a number every time the button is pressed.

Gate[]

Assign a value to a button

A button usually has a value of 0 when not pressed, and 1 for a short amount of time when pressed. This circuit makes the button have 0 when not pressed and an arbitrary number when pressed.

Dual Value Gate[]

Value is 3 when not pressed, and 7 when pressed.

This circuit replaces the button output by arbitrary numbers. The example results in 3 when unpressed, and 7 when pressed.

Pulse/Steady Conversions[]

Pulse to Steady[]

Ring Based[]

A simple ring store can be used to convert a value pulse to a steady value signal. Dice for example output the rolled number for a single tick and then output 0 again.

However when you use the simple ring store, you have to be sure that there will be no new pulse until the old value is reset. Otherwise use this:

PulseToSteady

This circuit always stores the last non-zero value. This circuit can be affected by the Ring Evaluation Order issue.

RNG Based[]

RngStore

This circuit performs the same function as the one above, see RNG Store for differences.

Steady to Pulse[]

Delay Based[]

SteadyToPulseTimer

A delay chip can be used to convert a steady input to a single tick pulse. Every time the input changes, the delay outputs that value for a single tick and then outputs 0 again. It is worth noting that the delay chip does always delay the signal by exactly one tick, but up to five ticks.

Ring Based[]

SteadyToPulse

This circuit does the same, but emits the pulse in the same tick that the value changes and outputs 0 in the second tick. It can be affected by the Ring Evaluation Order issue.

Copy Value[]

Ring Based[]

CopyValue

This circuit takes an input value from the left and copies it to the ring store on the right when a signal is triggered. The circuit can be affected by the Ring Evaluation Order issue. In that case the result is the same, but delayed by one tick.

RNG Based[]

CopyValueRng

This circuit performs the same function as the one above, see RNG Store for differences.

On and Off Switches[]

Toggle[]

Toggle

The button toggles the output between 0 and 1. Use this variant with caution: It keeps toggling as long as there is a 1 input. Therefore, only use 1-tick-long pulse signals to trigger it. However this behavior might also be useful when it is possible that two consecutive ticks trigger the toggle signal, with no 0 in between.

Separate Switches for On and Off[]

See RS Latch.

The top button always sets the output to 1, and the bottom button always sets the output to 0.

State Cycle[]

StateCycle

The button cycles the output between an arbitrary number of states. In this example the output can have 3 states: 0, 1 and 2. If the number of states is set to 2, this behaves like the Toggle circuit above, therefore the State Cycle is a generalization of the Toggle circuit.

Room Initializaion[]

RoomInit

This circuit outputs a 1 pulse when a new room instance is created, or the room is saved or restored. This allows you to execute some initialization routines, e.g. moving a piston to a certain starting point.

Logical Plus/Minus[]

Logic1

Often you don't need 1 or 0 as a result of a logic comparison or Boolean operation, but 1 or -1.

Absolute Value[]

Abs

Produces the absolute value of an arbitrary input.

High Score[]

Highscore

The left ring is a placeholder for the current score. If the score is higher than the current high score, the high score is immediately adjusted. The circuit contains rings and therefore might be affected by the Ring Evaluation Order issue.

Cooldown Button[]

CooldownButton

A button that is disabled for 5 seconds after it was pressed. This circuit can be affected by the Ring Evaluation Order issue. Using the output of the multiply chip, however, is completely safe; the circuit will do what is expected regardless of Ring Evaluation Order.

Multiplexer (Inverse Selector)[]

Untitled-0

Whereas a Selector chip by itself chooses among 7 outputs, this circuit chooses among the 7 input pins of the Combinator chips and passes that input along to a single output. The green input pin of the Selector chip should receive a continuous value of 1. This is useful for choosing among ascertained Player or Object IDs.

If multiple conditions are met within the Selector chip, they are totaled together for the ultimate output (this is not desirable for Player or Object IDs).

The Selector chip is essentially a demultiplexer. One could argue that the existence of a demultiplexer should imply the existence of a multiplexer. You can support that idea here.

Non-Repeating Random Number Generator[]

Untitled2-0

In the variable chip, the green pin is set to 1, and the blue pin is set to <range size>.

The RNG chip can produce the same number twice, but it is often desirable that a random number generator will not repeat itself. This circuit assures that each generated number is different from the last.

On every roll, the range for the next roll is redefined as [<generated value> + 1, <generated value> + <range size> -1]. This effectively excludes the generated value as a possibility on the next roll since the lowest possible next value is higher. When the generated value exceeds the range, a modulo chip "loops back around" so that the actual value output is still within the range. Because of the modulo chip, the output range will always be [0, <range size> - 1]; to change the ultimate range (for example, to assure that all numbers will be nonzero values) use a Combinator chip after the output.

A simpler alternative for this function is to store the last generated value and re-roll the RNG chip if the generated value is equal to the previous value. The disadvantage of that solution is that it requires an unpredictable amount of additional circuit ticks.

Event Sequence[]

Untitled2

Pressing the button begins a sequence of events. The events can occur at arbitrary times, configured in the Selector chip. Time is measured in circuit ticks (roughly 0.1 seconds). The pictured circuit will blink the top light at 0 seconds, the second light at 30 seconds, and the third light at 2 minutes (1200 ticks).

Note that time and circuit ticks diverge over time. If you need real time based events, use a timer chip instead and connect it's green output to the red selector input. This will not diverge from real time over time (except when looping), but only offer a 1 second accuracy.

Other events can be added to the remaining pins of the Selector, and the circuit will stop automatically after 3 minutes (1800 ticks). To create a looping sequence, simply connect the final event pin to the reset pin of the Combinator chip instead of the OR chip.

RS Latch[]

RsLatch

Sets the output to 1 when S is pressed and to 0 when R is pressed.

RS Flip-Flop[]

RsFlipFlop

When C is triggered changes the output to 1 if S is 1 or to 0 if R is 1.

JK Flip-Flop[]

JkFlipFlop

Like the RS Flip-Flop, but toggles the output state when C is triggered and J and K are 1. The circuit contains rings and therefore might be affected by the Ring Evaluation Order issue.

Gizmo State Sensor[]

GizmoState

When you stop and restart gizmos in the maker pen menu they will reset, but often not to any meaningful state. The concept above allows you to detect the maker pen gizmo state and act upon that, e.g. reset some more states. The red output of the trigger zone outputs a pulse when gizmos are started, the blue one when the gizmos are stopped, and the green pin outputs a constant 1 while gizmos are active and 0 while they are stopped.

Single Tick Delay[]

The official delay chip has a few characteristics that might not always be desired:

  1. It performs a steady-to-pulse conversion.
  2. It is time based and not guaranteed to delay for a specific amount of ticks.
  3. It takes time to initialize, sometimes up to 4 ticks.

SingleTickDelay

The above circuit delays the input unaltered by a single tick, and avoids all of the mentioned problems. This circuit exploits the Ring Evaluation Order problem to force the right chip to be evaluated before the input from the left is taken into account, which is therefore delayed by one tick.

To build this circuit, first draw the connection between the reset pins, afterwards draw the connection between the red pins. All input to the left chip will now be delayed by 1 tick before it is passed to the right chip.

Random Permutation[]

Random Permutation

This circuit generates a random permutation of 4 elements from the set {1, 2, 3, 4, 5, 6} . It evaluates in a single tick and can be adjusted to support larger sets without increasing the size of the circuit as long as only 4 elements are randomly selected from the set.

To pick 4 elements from a set {1, 2, 3, ... n-2, n-1, n}, the lower left variable chips should be adjusted to be n+1, n, n-1, and n-2 for the red, green, blue, and red pins respectively from top to bottom. The top center variable chip's red pin should be set to 1.

For completeness, to pick 4 elements from a set {n, n+1, n+2, ..., n+k-2, n+k-1, n+k}, the lower left variable chips should be adjusted to be n+k+1, n+k, n+k-1, and n+k-2 for the red, green, blue and red pins respectively from top to bottom. The top center variable chip's red pin should be set to n.

The circuit can be simplified if only picking 4 elements from a set, {1, 2, 3, 4} the bottom lower left variable chip can be deleted and the top lower left variable chip should be adjusted to be 5, 4, and 3 for the red, green, and blue pins respectively. The RNG chip in the upper right can be replaced with a variable input of 1, since the RNG chip would otherwise never generate anything but 1. The resulting simplified circuit looks as follows:

Lehmer Permutations

The functionality of this circuit is based on the Lehmer Code representation of permutations where the 3 variable chips pick a random number for the digit in the code and then the following function is used to generate the permutation from that code:

For each entry x, in order from right to left, correct the items to its right by adding 1 to all those (currently) greater than or equal to x; finally interpret the resulting permutation of {0, 1, … n − 1} as sequence numbers (which amounts to adding 1 to each entry if a permutation of {1, 2, … n} is sought).

Expanding the circuit to support picking more than 4 elements is possible by expanding the current pattern of chips at a cost of O(n2).



Click here for an interactive demo of the circuit. The circuit is available in the invention store under the titled: "Permutation Circuit".

Specific Functions[]

Disco Light[]

DiscoLight

The stage light changes color to a different color every second. The color sequence is fixed.

Random Disco Light[]

DiscoLightRandom

The stage light changes color to a random color every second. You can replace the Random chip by a Non-Repeating Random Number Generator if you want to make sure the color changes every tick.

Spawn On Hit[]

SpawnOnHit

This circuit will respawn any player hit by a weapon. At least one respawn point from the sandbox has to be present in order for the player to respawn.

Spawn On Non-Self Hit[]

NoSelfHit

This circuit will respawn a player that has been hit if they are not the attacker.

Spawn On Different Team Hit[]

NoFriendlyFire

This circuit will respawn a player that has been hit if the attacker is on the opposing team.

Teleport Button[]

TeleportPlayer

Instantly teleports the player who pressed the button the spawn point.

Random Teleport Selection[]

TeleportPlayerRandom

Teleports the player who pressed the button to a randomly selected spawn point.

Checkpoints[]

Checkpoints

The buttons can of course be replaced by goals. Each button that is pressed activates the next one. When the last button is pressed, it outputs 1 for a short time to the lower output, increments the lap counter at the top and resets all buttons.

The number of checkpoints can be extended by repeating the sequence of button 2 (button, AND, Plus).

Number Pad[]

Numpad

This circuit realizes an integer input field, using one button per digit. It could be used for example to create a calculator or a door pin code.

The "From [number]" lines indicate a connection to a button with that number. Each OR chip on the left represents one digit in the binary representation button number. Therefore a button can be connected to multiple chips.

Implementation Note: This circuit can be affected by the Ring Evaluation Order issue.

HP Management[]

SimpleHp

A simple HP tracking implementation, in an elimination-style fashion. 250 HP are assigned to every player on game start, once a player reaches 0 HP he dies and cannot move anymore until the game ends. Note that there is no game end condition.

The currently most complete demonstration of what can be done can be found in the ^testhp4 room. If you are planning to create a room in the Maker Room and use some kind of HP management, chances are good that the demo supports that. It is fully configurable with variable chips, so you can request to clone it and might save some work.

Smooth Wave[]

Winker

It is surprisingly hard to create a smooth waving motion with the wave chip, although it appears to be designed to do exactly that. This circuit makes a rotator wave smoothly in a sine fashion from -45° to 45°. It is self-stabilizing and does not run out of those bounds over time. The circuit contains rings and therefore might be affected by the Ring Evaluation Order issue.

Digital Clock Display[]

Untitled-1

Configure the Sign prop so that Message 0 is {R}:{G} and Message 1 is {R}:0{G}.

A Timer chip can only output the number of seconds remaining in a countdown. Use this circuit to convert a number of seconds to the MM:SS (minutes:seconds) format of a digital clock. Remaining seconds divided by 60 represents the number of minutes remaining. Remaining seconds modulo 60 represents the number of seconds remaining in the current minute. The Comparer chip detects when fewer than 10 seconds will be displayed, and changes the Message format to add a "0" placeholder in the tens place.

This specific clock will not display hours, but instead shows the number of minutes regardless of whether there are more than 60. An hour display is possible using a circuit that is analogous but more complicated.

Extending this Page[]

Feel free to add more diagrams to this page.

Different people have created templates that you can use to draw circuit diagrams if you like:

Alternatively, you can use the Rec Room Circuit Simulator (RRCS) to draw circuit diagrams.

Advertisement