我正在尝试在Spark AR中为我的游戏提供计分功能,但是promise.all似乎不起作用

问题描述

我对编程非常陌生,我试图使用脚本来修补桥接技术。我不知道为什么这不起作用,这是我的代码

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.

这是控制台日志中的错误

改为使用PatchesModule.outputs.getScalar! @ HermesRuntime

不建议使用此API,请升级到最新的SDK版本。讯息:

@
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}

请帮助我,谢谢

解决方法

  1. GameScore从修补程序接收一个数字值,并将其发送到脚本。
  2. ScoreText从GameScore获取值并保留它。
  3. outputScore从ScoreText中获取值,并将其发送回补丁。
  4. 然后在补丁中,将outputScore补丁连接到sampletxt的文本补丁。

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