I am trying to make scoring function for my game in spark ar, but promise.all doesn't seems to work

611 views Asked by At

im very new to programming, im trying to use script to patch bridging technique. i have no idea why this doesn't work, here's my code:

const Scene = require('Scene');
const Patches = require('Patches');
export const Diagnostics = require('Diagnostics');

const patchValue = Patches.getScalarValue('GameScore');

Promise.all([
    Scene.root.findFirst("sampletxt"), 

   ]).then(function(results){
    
    var ScoreText = results[0];
    ScoreText.text = patchValue.toString();

    }); 

Diagnostics.watch('runtime -', patchValue); // im using this line to see if the script reads the value from patch.

here is the error from the console log:

Use PatchesModule.outputs.getScalar instead! @ HermesRuntime

This API is deprecated, please upgrade to the newest SDK version. Message:

@
HermesRuntime

Possible Unhandled Promise Rejection: Unexpeted SceneObject reference: {"identifier":"2_d_text_model:7030-1be1a0e4-3bb6-4a3b-bc9c-e17b7b57aa6c","name":"sampletxt","materialIdentifier":"","className":"planarText","modelId":505}

Please help me, thank you

1

There are 1 answers

1
Philip Yong On
  1. GameScore receives a number value from Patches and sends it to Script.
  2. ScoreText takes the value from GameScore and keeps it.
  3. outputScore takes the value from ScoreText and sends it back to Patches.
  4. In the Patches, we then connect the outputScore Patch to the sampletxt's text Patch.

Patches Layout

const Patches = require("Patches");

//onStart Set GameScore Value
Patches.outputs.getScalar("GameScore").then((event) => {
  var ScoreText = event.pinLastValue();
  Patches.inputs.setString("outputScore", ScoreText.toString());

  //onChange Update GameScore Value
  event.monitor().subscribe(function (values) {
    ScoreText = values.newValue;
    Patches.inputs.setString("outputScore", ScoreText.toString());
  });
});