You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:解决HTML/JS格斗游戏开发中的两类报错问题

两类错误的排查与解决

1. 调试器提示“No debugger available, can not send 'variables'”

  • 确保launch.json配置正确,调试目标需指向本地服务器地址(如http://localhost:5500),而非本地文件路径(file:///开头的路径),Chrome调试器对本地文件的调试支持有限。
  • 检查配置中的type字段,需匹配你使用的浏览器(如chrome或msedge),request设为launch,并保证webRoot指向项目根目录。正确配置示例:
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Launch Chrome against localhost",
      "url": "http://localhost:5500",
      "webRoot": "${workspaceFolder}"
    }
  ]
}
  • 启动本地服务器(比如用VS Code的Live Server插件),确保服务器端口与launch.json中的url端口一致。

2. Uncaught ReferenceError: height is not defined

  • 遍历index.js中所有使用height的代码,确认该变量已通过let/const/var声明,避免拼写错误(比如误写为heigth)。
  • 如果height是Canvas元素的属性,需先获取Canvas元素再赋值,示例:
const canvas = document.querySelector('canvas');
const height = canvas.height; // 声明并初始化height变量
  • 检查变量作用域:如果height是在某个函数内部声明的,外部无法直接访问,需调整作用域(比如把变量声明移到函数外)或通过参数传递。

内容的提问来源于stack exchange,提问作者Jad Miri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 13:14:57