2

I am trying to link a device motion value to a 2D Text element, so that the rotation Y value will appear as text in my scene.

I've been trying to implement a solution described in another thread, with no luck. Apparently since v85 was released in March 2020 there have been some changes to how scripting works in Spark AR.

This is the code I used in my project:

const Patches = require('Patches');

const numberFormat = 'Time: {0}';
const number = Patches.getScalarValue('number');

Patches.setStringValue('value', number.format(numberFormat));

This is what my script looks like in the editor

Patch I used

My To and From script values

If anyone knows why the script is not working, please help me out.

janwys
  • 21
  • 1

1 Answers1

2

The API changed to Promise based. This means that Patches.getScalarValue() will give you a Promise. This script should work:

const Patches = require('Patches');

// enable async/await 
(async () => {
const numberFormat = 'Time: {0}';
const number = await Patches.getScalarValue('number');

Patches.setStringValue('value', number.format(numberFormat));

})()

Also you didn't provide the error from SparkAR Studio.

lisichka ggg
  • 563
  • 3
  • 15