繁体   English   中英

我正在尝试在 spark ar 中为我的游戏制作评分功能,但 promise.all 似乎不起作用

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

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

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 @爱马仕运行时

此 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 从 Patches 接收一个数值并将其发送到 Script。
  2. ScoreText 从 GameScore 获取值并保留它。
  3. outputScore 从 ScoreText 获取值并将其发送回 Patches。
  4. 在补丁中,我们然后将 outputScore 补丁连接到 sampletxt 的文本补丁。

补丁布局

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM