# Registers

{% hint style="success" %}
Use Registers to alter the state of Nodes or influence the flow of Resources based on the computation of multiple inputs coming from either Nodes in the diagram or your own input during a diagram Step-by-Step Run.
{% endhint %}

Registers can be `passive` or `interactive`. Set their state in the Properties panel under Functional, by ticking "Interactive" ON or OFF.

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-MLrlbFweSS8X3eHtFlU%2F-MLrqya8DiJDActcF550%2Fimage.png?alt=media&#x26;token=2f6543ee-da79-4e93-a835-21af8264b483" alt=""></div>

By default, Registers are `passive`.

## Passive Registers

`Passive` Registers may gather input from multiple origin Nodes, compute them based on formulas and influence the state of other Connections or Nodes within the diagram.

Each Register input State Connection is assigned a letter Label. Use these identifiers as variables in the formula the Register needs to compute.

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-M60ayvaRMKZpDAWbmic%2F-M60r3-AFTI4tq1gN62k%2FScreen%20Recording%202020-04-28%20at%2008.35%20PM.gif?alt=media&#x26;token=23d14eca-3129-48a9-be0a-5729415245fe" alt=""></div>

:bulb: Note above that when the diagram is running the Register displays the computed result, before the run, it displays ***fx.***

### Properties

**Label**

For `passive` Registers the Label is used to input the formula you want to compute.

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-MLrlbFweSS8X3eHtFlU%2F-MLrsTLtv5OXkOc5vo7d%2Fimage.png?alt=media&#x26;token=4075bded-9435-4635-9599-f614e043d78e" alt=""></div>

:man\_mage: Registers support functions from the [math.js library](https://machinations.gitbook.io/docs/registers/math.js-functions).

## Interactive Registers

A Register becomes `interactive` when the "Interactive" option is ticked in the Properties panel, under Functional.

After ticking the "Interactive" option Registers become editable during [Step-by-Step Runs](https://machinations.gitbook.io/docs/simulations/simulations#2-step-by-step-run). Use the upward and downward arrows <img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-M61AgXM2kfRpKeuIU8d%2F-M61DOcZ-xoehQ-BFxHp%2Fimage.png?alt=media&#x26;token=f0e7976f-0f6e-4d98-af22-ea759fbebb1b" alt="" data-size="original"> to interact and change a Register's value.

### Properties

**Label**

The Label for an `interactive` Register has a purely descriptive function. Use it to describe what the Register stands for.

#### Limits

Use a `minimum` and/or a `maximum` value under and/or over which the Register doesn't allow changes.

![](https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-MLrsbp_y1qH1OGdXWQz%2F-MLs7b1JPfY0yRKv4qxM%2FScreen%20Recording%202020-11-11%20at%2006.27%20PM.gif?alt=media\&token=dc87703c-128a-46b9-8e14-4c16cd6cae0b)

#### Value

Upon ticking on "Interactive", two properties become available for `interactive` Registers:

* [x] ***Initial Value*** - sets the value the Register passes on upon running the diagram
* [x] ***Step Value** -* sets a multiplier for each interaction with the Register

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-M61EBYsRDfBxRYXU4TX%2F-M63s8WoRdmoKuz6n_Yp%2FScreen%20Recording%202020-04-29%20at%2010.38%20AM.gif?alt=media&#x26;token=f7a462a3-05ee-4044-b0cd-d788ded484db" alt=""></div>

> In the example above, the interactive Register has a set initial value of 3, and a step value of 2. With each interaction, the Register changes its value (in real-time, during the diagram Step-by-Step Run) with +/-2.

#### Show In Chart

Tick "Show in Chart" (option also available in the contextual menu at right click) to plot the values taken by the Register at each Time Step when running the diagram.

## Examples

### 1. Multiplying target value

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-MMGt7wKjc0vLcY9hHv_%2F-MMH-R8Oq4kEZ_HHElCk%2FScreen%20Recording%202020-11-16%20at%2007.01%20PM.gif?alt=media&#x26;token=843791de-ef5e-433f-888d-eb3112d40f95" alt=""></div>

In the example above we are multiplying the Target value (the flow of Resources from Source to Pool). To obtain this, we used an `interactive` Register with a Step Value equal to the Target's value. In order to have an integer x multiplying factor, we used "100%" as a Label on the State Connection.&#x20;

This results in the Target being multiplied by the number of steps that the user interactively changes on the Register during run time.

:bulb: Note: for those looking for the deprecated m operator, this method generates the same effect. If you need to multiply functions on the Target, then the Origin needs to be a `passive` Register with a formula identical to that of the Target.

### 2. Using math.js functions

#### Basic calculations

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-M63t-MSICiVv8XFJliI%2F-M6486UYEkX-mScY9g7u%2Fimage.png?alt=media&#x26;token=750dfc87-1d41-4753-9023-3dd70c6aaa2b" alt=""></div>

1. `add(a,b)` adds the values of a and b&#x20;
2. `subtract(a,b)` subtracts b from a
3. `multiply(a,b)` multiplies the values of a and b&#x20;
4. `divide(a,b)` divides a by the value of b

####

#### Exponential functions

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-M63t-MSICiVv8XFJliI%2F-M6494gNekK4fyZoys9s%2Fimage.png?alt=media&#x26;token=06dc1828-6a22-4fed-8569-83a58f3ddd1b" alt=""></div>

1. `square(a)` returns the square value of a (a\*a)
2. `cube(a)` returns the cubic value of a (a\*a\*a)
3. `sqrt(a)` returns the square root of a
4. `cbrt(a)` returns the cubic root of a
5. `pow(a,b)` returns the value of a raised to the power of b

:man\_mage: For more examples on using math.js functions with Registers, access the **public diagram** [**Framework: Register and math.js functions**](https://my.machinations.io/public/Framework:-Register-and-math-js-functions/085f9d96de8c597c9bd2a4894c825faba), or find it in `File > New from Template > Framework: Register and math.js functions`

### 3. If Statements

If you're trying to model complex `if statements`, you can use Registers to calculate conditions. You can find an example for both context and solution, in the article on [how to emulate the Artificial Player](https://machinations.gitbook.io/docs/artificial-player#2-if-statements) legacy component, with machinations.io Nodes and Connections.
