Circuits V1

Circuits V1(CV1) is the first scripting language created for the online game Rec Room.
It was not intended as an esoteric programming language, but has many questionable design choices which lend it strongly esoteric traits.
__TOC__
==History==
CV1 was introduced into Rec Room on February 15, 2018, with the "Merch Booth" update.https://store.steampowered.com/news/app/471710/view/4041374038287315538
Originally it was only capable of simple computation, however updates down-the-line allowed for more broad interactions with the world.
It was eventually replaced by the release from beta of Circuits V2 on May 3, 2021, though, at time of writing, it remains in the game.https://store.steampowered.com/news/app/471710/view/3049476328796187455
==Program Structure==
CV1 code is made from a variety of objects existing in the game world, each having some set of pins.
===Pins===
All CV1 elements contain some set of pins.
A pin is either an input or an output, and contains a single value.
An output pin may be connected("Wired") to an arbitrary number of inputs, but an input is limited to a maximum of 1 wire.
Most input pins allow you to set an arbitrary connectionless input, with a small circle adjacent to them showing the current configured input. This is sometimes ignored, as certain ports will only have an effect if they are actually wired to something. This behaviour is done to ignore the default 0 value, which would otherwise render many chips unusable.(AND, Lights, etc.)
===Chips===
Chips are the main method of computation in CV1, and are rendered as a black rectangular prism with the front-facing left and right edges beveled.
Chips come in 4, 6, and 8 pin varieties. A 4-pin chip may have up to 4 inputs and 4 outputs, but this is not required, and many chips do not take advantage of their allotted ports.
Many chips include a reset line. This is usually a white input and output, labelled with a black 'R', at the bottom of the chip(regardless of the size/what pins are used by the chip).
The reset line will clear the internal state of the chip, and any inputs/outputs will be zeroed while it is held true.
===Gadgets===
Gizmos, gadgets, and circuits are terms used somewhat interchangeably.
For the purposes of this article: Gadgets refer to any non-chip CV1 element, circuits refers to CV1, and gizmos refer to the following subset of gadgets:
* Piston
* Rotator
* Clamp
* Look At
* Animation Gizmo
The game setting "Show Gadgets when not holding the Maker Pen" applies to all circuitry, not just gadgets.
Gadgets operate in a similar way to chips, but instead of their inputs affecting their outputs, their inputs tend to affect their state in the game world. For example, the light has no output, but its intensity will be set to its "Intensity" input on each tick.
For gadgets who's model is only rendered to people who can see gadgets, usually pins matching the style of chip pins are added to the mesh. For gadgets who's model is rendered to normal players, usually pins are rendered as holographic arrows.
==Execution Model==
CV1's execution operates under the idea of "ticks". Ticks are fired at 10hz, OS scheduling notwithstanding. On each tick, the graph is evaluated and input/output values are updated accordingly. Any signals generated by this are fired on the tick as well.
Generally, a sequence of simple computation chips will lead to the full sequence being executed in one tick. In the case of a data-dependency loop, Execution will halt at the first chip that has already been executed. CV1 has no concept of a null or empty value, so uncomputed data is assumed to be 0.
===Authority===
Rec Room's servers act like a sort of relay for clients, only synchronizing location and rotation info, and distributing events. Due to this, CV1 is not executed on the server. Instead, the player with the superior hardware is chosen to execute CV1 for the entire room, called the "Room Authority". Due to this, CV1 may act inconsistently when the Room Authority changes, lags, or incurs any other odd behaviour.
===Signals===
CV1 has a notion of signals. Signals may operate differently between specific chips, but generally follow one of the following conventions:
# The rising edge of a true boolean is considered a signal.(e.g. Show Notification)
# The rising edge, and all subsequent ticks with a true value, are considered signals.(e.g. Pulse Randomizer)
# The change from any value to any value to any other value that is true is considered a signal. (e.g. Delay)
If conventions 1 or 3 apply, and a true value is held during transition of Room Authority, generally this will result in a repetition of the signal.
All signal-producing chips will output a 1 when sending a signal, though all will accept any true value as a signal.
==Datatypes==
Technically, CV1 has only one datatype, that being a signed 32-bit integer. Despite this, many chips will treat this number in a special way.
Due to this, CV1 supports additional datatypes which are encoded as integers.
===Booleans===
Like in many languages, CV1 stores booleans as a nonzero value being true, and a zero value being false.
Any chips involving boolean logic will output either a 1 or 0.
===Player IDs===
CV1 has no concept of references or objects, instead encoding the players in the room as IDs.
There is no easy way to test if an ID does or does not refer to an existing player, nor what the current min/max ID is.
This must be manually computed by the circuiteer in question.
IDs are assigned sequentially, from 1, and not reused when free. Consider the following events:
# Alice joins the room.
# Bob joins the room.
# Alice leaves the room.
# Clark joins the room.
# Alice rejoins the room.
This would result in the following player IDs:
 1: Unassigned
 2: Bob
 3: Clark
 4: Alice
The next player to join would be assigned ID 5.
===Object IDs===
Similar to players, all objects in a room have IDs. These are assigned arbitrarily to objects.
Players have certain objects assigned to them that they carry between all rooms. These can be accessed with the following:
 100000 * Player ID + Object Index
Where Object Index is one of the following:
 12: Camera
 13: Maker Pen
 17: Feedback Tool
==Example Graphs==
* Hello World
* Truth-Machine 
* 4-op Calculator
* Exponentiation
==Implementations==
Being nonstandardized and part of a closed-source game, CV1's primary testing software is the game it's from, Rec Room. There is also a very accurate open-source implementation called The Rec Room Circuit Simulator(RRCS). All provided examples are implemented in this software.
Category:Languages