Search code examples
javascriptspark-ar-studio

Score Didnt show up (Spark AR)


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();

Solution

  • 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.