[2026/5/22 22:14:00] Print:--------------------ErrorHandler-----------------------
[2026/5/22 22:14:00] Print:...\P2\MirServer\Mir200\Envir/Custom/module/TG/血战沙城.lua:329: attempt to call a nil value (method 'checkTime')
[2026/5/22 22:14:00] Print:---
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-05-22 13:01:28 |
👁️ 阅读: 0
我是lua后端老师!
小仙,看了你的错误日志,问题出在 `XueZhanShaCheng:onTimer7` 函数中调用了 `self:checkTime(actor)`,但你的 `checkTime` 函数定义有问题。
在你的代码中,`checkTime` 函数被定义为了一个全局函数(`function XueZhanShaChengcheckTime(actor)`),而不是作为类的方法。正确的类方法定义应该是 `function XueZhanShaCheng:checkTime(actor)`。
修改方法如下:
```lua
-- 错误写法(这是全局函数)
function XueZhanShaChengcheckTime(actor)
local hour = tonumber(getconst(actor, "<$Hour>"))
local minute = tonumber(getconst(actor, "<$MINUTE>"))
release_print("当前时间:", hour, ":", minute)
if hour ~= 20 then
Msg.richMsg(actor, "当前不在攻杀期间!")
return false
end
return true
end
-- 正确写法(这是类方法)
function XueZhanShaCheng:checkTime(actor)
local hour = tonumber(getconst(actor, "<$Hour>"))
local minute = tonumber(getconst(actor, "<$MINUTE>"))
release_print("当前时间:", hour, ":", minute)
if hour ~= 20 then
Msg.richMsg(actor, "当前不在攻杀期间!")
return false
end
return true
end
```
另外,我还注意到你的代码中有几个地方需要优化:
1. **定时器注册问题**:你在 `init` 函数中注册了全局定时器处理器,但 `checkTime` 方法可能无法被正确调用。
2. **函数命名不一致**:你有一个 `onZeroTimer` 函数,但注册的是 `onTimer7`,这可能导致混淆。
3. **全局定时器**:你使用了 `ontimerex100` 作为全局定时器,但需要在 QF 中注册这个触发。
建议你检查一下函数定义,确保所有类方法都使用 `:` 语法定义。下次写代码时要注意函数的作用域和调用方式,不懂的可以问你师傅浮生梦尊师哦!
← 返回问答库