Script to Patch Bridging

You can pass information between scripts and the Patch Editor by adding shared variables.

There are 7 variable types supported with some type differences between the Patch Editor and script:

Patch Editor typeScript type

Boolean

Boolean

Number

Scalar

Pulse

EventSource

Text

String

Vector 2

PixelPointSignal

Vector 3

VectorSignal or PointSignal

Vector 4

RgbaSignal

Shared variables can be created from the Inspector Panel after selecting a script file in the Assets Panel.


Sending variables from scripts to the Patch Editor

Sending

To send a variable from a script to the Patch Editor, use the set methods provided by the Patches Module.

The following example shows a Boolean being sent from a script to the Patch Editor:

// Load in the patches module
const Patches = require('Patches');

// Create a boolean variable
const myBoolean = true;

// Send the boolean to the Patch Editor under the name 'myBoolean'
Patches.setBooleanValue('myBoolean', myBoolean);

Accessing

To access a variable sent from a script in the Patch Editor:

  1. Select the script file in the Assets Panel.
  2. In the Inspector Panel, to the right of From Script, click + to add a new variable.
  3. Change the variable name to match the name of the variable defined in your script.
  4. Under Interactions select Create Producer Patch.


This will create a purple producer patch with any variables you have defined under the From Script section as outputs. You can connect the output port(s) to other patches.

Sending variables from the Patch Editor to scripts

Sending

To send a variable from the Patch Editor to a script:

  1. Select the script file in the Assets Panel.
  2. In the Inspector Panel, to the right of To Script, click + to add a new script variable.
  3. Change the variable name to match the name of the variable that will be used in the script.
  4. Click the arrow next to the variable.


This will create a yellow consumer patch, the value of which can be read inside the script. You can connect other patches to the input port to change the value.

Accessing

To access a variable sent from the Patch Editor in a script, use the get methods provided by the Patches Module.

The following example shows Text being accessed in a script from the Patch Editor:

// Load in the patches module
const Patches = require('Patches');

// Get the 'myText' string from the Patch Editor
const myString = Patches.getStringValue('myText');