javascript - 我正在尝试在 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
!@爱马仕运行时
此 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}
请帮助我,谢谢
解决方案
- GameScore 从 Patches 接收一个数值并将其发送给 Script。
- ScoreText 从 GameScore 获取值并保留它。
- outputScore 从 ScoreText 中获取值并将其发送回 Patches。
- 在补丁中,我们将 outputScore Patch 连接到 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());
});
});
推荐阅读
- reactjs - 无法将项目添加到本地存储
- python - Python Telebot 不发送消息
- error-handling - 如何使用 eclipse 2020 09 创建自定义错误处理程序
- javascript - 提交事件“TypeError:无法读取未定义的属性‘值’”的笑话测试
- android - Android 电子邮件意图忽略换行符(“\n”或“
”?) - python - 运行此“从文件读取”代码时,为什么会出现“str”对象没有属性“readlines”错误?
- java - Java 子对象存储在父变量中。为什么它调用子方法而不是调用父方法?
- python - 模糊推理系统 python
- c# - 如何在 Windows 窗体中将变量从一种形式继承到另一种形式?
- elasticsearch - 比较两个 elasticsearch 的设置内容