This example is provided by Andrey Staroseltsev Facebook post that shows how to use the Spark AR Patch to Script editor.
Below are some useful examples :
AR Studio v38 now has an ability to have shared context between the Script and the Patch Editor.
AR STUDIO SIDE:
From the Script Inspector of AR Studio it is now possible to declare variables to be used in both Script & the Patch Editor for reading as well as writing.
– “From Script” variables allow to get (read) JS signals inside the Patch Editor by having a Producer patch.
– “To Script” variables allow to set (write) JS signals inside the Patch Editor by having a Consumer patch
Check out a video 🎬 attached to see this in action
Import the newly added Patches module in your script:
var P = require(‘Patches’);
Write to signals:
// Set a signal:
// Or set a constant:
P.setVectorValue(“vectorVar”, R.vector(-10, 20, -10));
Read from signals:
// Get a signal
var boolSignal = P.getBooleanValue(“boolVar”);
var scaleSignal = P.getScalarValue(“scaleVar”);
var vectorSignal = P.getVectorValue(“vectorVar”);
var eventSource = P.getPulseValue(“triggerVar”);
Full module documentation available here: