2

i try write some code to view the score on Spark AR but it not show up on spark editor, and there`s no error on code

whats wrong? can you help me?

const Scene = require('Scene');
const P = require('Patches');
const R = require('Reactive');

var SKAWNum = Scene.root.findFirst('test');
var scoreNum = P.outputs.getScalar('score');

SKAWNum.text = scoreNum.toString();
  • What do you mean when you say `it did not show up` – Michael Nelles Apr 08 '20 at 03:06
  • it doesnt make a change on the viewer windows on spark, after the APIs updated all the script must be converted to new APIs, but after i convert to new APIs, This things happened – Billy Putra Apr 08 '20 at 03:12
  • its still show me tahts the score still same '0' even the counter value show me 50, in the preview windows on spark its still 0 – Billy Putra Apr 08 '20 at 03:16

1 Answers1

1

From what I can see you are accessing/getting the patch scalar value incorrectly and the findFirst is used incorrectly.

Your code:

const Scene = require('Scene');
const P = require('Patches');
const R = require('Reactive');

var SKAWNum = Scene.root.findFirst('test');
var scoreNum = P.outputs.getScalar('score');

SKAWNum.text = scoreNum.toString();

Here's how you should do it:

const Scene = require('Scene');
const P = require('Patches');
const R = require('Reactive');

var SKAWNum = Scene.root.find('test');
var scoreNum = P.getScalarValue('score');

SKAWNum.text = scoreNum.toString();

if the Scene.root.find doesn't work then visit this page which has an example of how you use the findFirst which the find from the code above could also be replaced with.

  • Hi, I had the same issue and this answer didn't work. Since the new update, "find" is not available and findFirst,findAll,findByPath are the methods available. And I'm getting the error "Property 'text' does not exist on type 'Promise'." – Prabhashi Buddhima May 20 '21 at 14:56