As a result of the coronavirus (COVID-19) outbreak, we have a reduced capacity to review effects and delays in publishing are expected. Learn more.
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 type||Script type|
Shared variables can be created from the Inspector Panel after selecting a script file in the Assets Panel.
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);
To access a variable sent from a script in the Patch Editor:
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.
To send a variable from the Patch Editor to a script:
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.
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');