[SAPI求助]JavaScript帮忙找哪里错了
服了啊,写了一下午的代码,最后还是没有成功运行,看了报错日志也没有看懂,谁可以看看我哪里写错了:import { world, system } from "@minecraft/server"
import { ActionFormData, MessageFormData, ModalFormData } from "@minecraft/server-ui"
world.beforeEvents.itemUseOn.subscribe((event) => {
const huchu = event.itemStack
const player = event.source
if (item.typeId == `minecraft:snowball`) system.run(() => Action(player))
function Action(player) {
const Action = new ActionFormData()
.title(`SAPI测试1|作者KLPBBS星空晶体`)
.body(`下方测试`)
.button(`时间设置`)
.button(`效果设置`)
.button(`清除设置`)
.button(`矿物给予`)
.button(`当前位置设置重生点`)
.button(`游戏模式`)
.show(player)
.then((Action) => {
if (Action.selection == 0) {
timeshzh(player)
}
if (Action.selection == 1) {
effectshzh(player)
}
if (Action.selection == 2) {
killshzh(player)
}
if (Action.selection == 3) {
oregiving(player)
}
if (Action.selection == 4) {
player.runCommand(`setworldspawn`)
}
if (Action.selection == 5) {
mode(player)
}
})
}
function timeshzh(player) {
const timeshzh = new ActionFormData()
.title(`时间设置`)
.body(`下方设置`)
.button(`日出`)
.button(`白天`)
.button(`正午`)
.button(`傍晚`)
.button(`夜晚`)
.button(`午夜`)
.show(player)
.then((timeshzh) => {
if (timeshzh.selection == 0) {
player.runCommand(`time set sunrise`)
player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间: 日出`}]})
}
if (timeshzh.selection == 1) {
player.runCommand(`time set day`)
player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间:白日`}]})
}
if (timeshzh.selection == 2) {
player.runCommand(`time set noon`)
player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间:中午`}]})
}
if (timeshzh.selection == 3) {
player.runCommand(`time set sunset`)
player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间: 傍晚`}]})
}
if (timeshzh.selection == 4) {
player.runCommand(`time set night`)
player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间: 夜晚`}]})
}
if (timeshzh.selection == 5) {
player.runCommand(`time set midnight`)
player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间: 正夜`}]})
}
})
}
function effectshzh(player) {
const effectshzh = new ModalFormData()
.title(`药水效果`)
.toggle(`瞬间治疗`,false)
.toggle(`夜视`,false)
.toggle(`饱和`,false)
.toggle(`抗性`,false)
.toggle(`生命恢复`,false)
.toggle(`速度`,false)
.toggle(`水下呼吸`,false)
.toggle(`力量`,false)
.toggle(`隐身`,false)
.toggle(`跳跃增强`,false)
.toggle(`急迫`,false)
.toggle(`抗火`,false)
.show(player)
.then((effectshzh) {
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} instant_health 99999 255 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} night_vision 99999 255 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} saturation 99999 255 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} resistance 99999 255 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} regeneration 99999 255 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} speed 99999 10 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} water_breathing 99999 255 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} strength 99999 255 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} invisibility 99999 255 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} fire_resistance 99999 255 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} jump_boost 99999 10 true`)
}
if (effectshzh.formValues == true) {
player.runCommand(`effect ${player.nameTag} haste 99999 10 true`)
}
})
}
function killshzh(player) {
const killshzh = new ActionFormData()
.title(`清除目标选择`)
.button(`清除随机玩家(需多人)`)
.button(`清除所有玩家`)
.button(`清除所有实体`)
.button(`清除命令执行者`)
.show(player)
.then((killshzh) {
if (killshzh.selection == 0) {
player.runCommand(`kill @r`)
}
if (killshzh.selection == 1) {
player.runCommand(`kill @a`)
}
if (killshzh.selection == 2) {
player.runCommand(`kill @e`)
}
if (killshzh.selection == 3) {
player.runCommand(`kill @s`)
}
})
}
function oregiving(player) {
const oregiving = new ActionFormData()
.title(`矿物给予`)
.button(`没写,累[悲]`)
.show(player)
.then((oregiving) {
if (oregiving.selection == 0) {
player.runCommand(`say 偷懒一下,下个版本再写[滑稽]`)
}
}
}
function mode(player) {
const mode = new ModalFormData()
.title(`游戏模式`)
.dropdown(`模式选择`,[`生存`,`创造`,`冒险`,`旁观`],0)
.show(player)
.then((mode) {
if (mode.formValues == `生存`) {
player.runCommand(`gamemode survival`)
} else if (mode.formValues == `创造`){
player.runCommand(`gamemode creative`)
} else if (mode.formValues == `冒险`) {
player.runCommand(`gamemode adventure`)
} else {
player.runCommand(`gamemode spectator`)
}
})
}
第4~9行
在第8行应加上"})"
第166~170行
应在170行后加上")"
在第98 146 179行需加入箭头(=>)
它的报错是什么发一下 话说你的scripts是用什么写的或从哪学的[抖音_494][抖音_494][抖音_494] ui写before事件外,大括号}少一个,报错可以百度或翻译 创作者界面保留错误日志打开然后看看报错,印象中好像可以看到行数的 条件有限只能简单排查
o 166行(170行)好像有个结束小括号缺少。
o 4行(8行)结束中括号和结束小括号缺少。
? 7行 if 后面好像要中括号包裹。
从语法能看到这么多暂时。
页: [1]