本帖最后由 指令凋灵 于 2023-1-29 10:58 编辑
这期我们来解决一下常见问题
如果你开启“开启内容日志GUI”
你在运行脚本时,如果脚本有问题屏幕上方就会有报错
这个报错对我们解决代码问题很重要
[Scripting][error]-Plugin [聊天检测 - 1.0.0] - [chat.js] ran with error: [SyntaxError: Could not find export 'Plaer' in module '@minecraft/server']
| | /*这个报错是变量名在"@minecraft/server"中没有,请检查第一行代码*/ |
[Scripting][error]-TypeError: cannot read property 'runCommandAsync' of undefined at <anonymous> (chat.js:2)
| | /*其中的<anonymous>指对象,一般为对象名错了,比如“t.sender”写成“t.sende”*/ |
[Scripting][error]-Plugin [聊天检测 - 1.0.0] - [chat.js] ran with error: [SyntaxError: expecting ';' at chat.js:2]
| | 这个指符号错了,其中的“at chat.js:2”指在chat.js中的系统认定的第二行代码,“expecting ';' ”指符号错误,请检查是否有语法问题和if、else等判定条件位置 |
[Scripting][error]-Plugin [聊天检测 - 1.0.0] - [chat.js] ran with error: [SyntaxError: unexpected token in expression: 'if' at chat.js:2]
| | /*这一般是if顺续不对*/ |
[Scripting][error]-ReferenceError: 'tru' is not defined at <anonymous> (chat.js:2)
| | /*意为没找到“tru”这个变量*/ |
注:如果你的代码是用bug运行,那就不要改了
还有:
此为脚本无响应引起的终止,解决方法有
1、删除行为包中的js文件
2、禁止后台运行或卡顿运行
3、这行代码可以解决:
| system.events.beforeWatchdogTerminate.subscribe(event => event.cancel = true); |
/*此代码运行需要写 1.19.40及以上:| import { system } from "@minecraft/server"; | 同开始时的import {world,Player} from "@minecraft/server",直接写
1.19.40及以下需要在“import{world,player}from "mojang-minecraft"中的“player”后加上“system”这个词(注:记得用,号分开)”
|