一、基础测试方法
1.实时运行测试
Ctrl + F9
快捷键或工具栏按钮启动地图测试2.高级测试命令
javascript
// 显示单位路径网格
ShowPathing
// 显示当前帧率
ShowFPS
// 立即胜利
AllyVictory
二、调试信息输出
1.结构化输出
javascript
// 带颜色分类的调试信息
Custom script: call DisplayTextToPlayer(GetLocalPlayer, 0, 0, "|cff00ff00[系统]|r 触发器"+I2S(udg_TriggerCount)+"已激活")
2.数据追踪面板
javascript
// 创建多行信息面板
Multiboard
Multiboard
三、高级调试技巧
1.条件断点模拟
javascript
If (DebugMode == true) then
call DisplayTextToForce(GetPlayersAll, "断点触发: " + GetTriggerEventName)
call PauseGame(true)
endif
2.事件追踪系统
javascript
// 注册全局事件监听
function TrackEvent takes nothing returns nothing
call DisplayTextToPlayer(GetLocalPlayer,0,0,"事件触发: "+GetHandleName(GetTriggeringTrigger))
endfunction
// 在初始化时绑定
call TriggerAddAction(gg_trg_MainEvent, function TrackEvent)
四、性能分析
1.执行时间测量
javascript
local real startTime = TimerGetElapsed(GetExpiredTimer)
// 执行待测代码
local real elapsed = TimerGetElapsed(GetExpiredTimer)
call DisplayTextToPlayer(GetLocalPlayer,0,0,"执行耗时: "+R2S(elapsed)+"秒")
2.内存监控
javascript
call DisplayTextToPlayer(GetLocalPlayer,0,0,"当前句柄数: "+I2S(GetHandleCount))
五、自动化测试
1.单元测试框架
javascript
// 测试用例容器
globals
integer udg_TestPassCount = 0
integer udg_TestFailCount = 0
endglobals
function AssertEqual takes integer expected, integer actual returns nothing
if expected == actual then
set udg_TestPassCount = udg_TestPassCount + 1
else
call DisplayTextToPlayer(GetLocalPlayer,0,0,"断言失败! 期望:"+I2S(expected)+" 实际:"+I2S(actual))
set udg_TestFailCount = udg_TestFailCount + 1
endif
endfunction
六、版本控制
1. 使用File -> Export Settings
导出触发器配置
2. 配合外部版本控制系统(如Git)管理不同调试版本
3. 通过注释块
标记调试修改:
javascript
//DEBUG-START v1.2.3
call SomeTestFunction
//DEBUG-END
常见问题排查清单:
1. 事件注册冲突检查
2. 变量作用域验证(全局/局部)
3. 单位/物品ID的拼写一致性
4. 计时器回调函数的作用域问题
5. 触发器的初始状态(是否禁用)
6. 玩家索引越界问题(特别是player(15))
建议结合使用JassHelper
进行语法检查,并通过WurstScript
或TypeScript for War3
等现代工具链提升代码可维护性。对于复杂项目,可使用Visual Studio Code
配合War3开发扩展实现远程调试。