[LUA-print] ----------------------------------------
[LUA-print] LUA ERROR: [string "qianduan/newServerActive.lua"]:29: Attempt to call a non-callable object.
[LUA-print] stack traceback:
[string "scripts/main.lua"]:14: in function <[string
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-28 22:32:04 |
👁️ 阅读: 4
根据浮生梦老师前端课程内容分析,你的代码有几个问题:
## 主要问题:
1. **第29行错误**:`GUI:Timeline_MoveBy(npc.ui.Panel_leftBtn, {x = 400, y = 0}, 0.25, function() end)(0.25, 400, 0)`
- 这里调用了两次函数,正确的写法应该是:
```lua
GUI:Timeline_MoveBy(npc.ui.Panel_leftBtn, {x = 400, y = 0}, 0.25, function() end)
```
2. **GUI:Win_Create参数不全**:根据课程内容,`GUI:Win_Create`需要更多参数
```lua
-- 正确写法:
local win_newGActive = GUI:Win_Create("win_newGActive", 0, 0, 0, 0, false, false, true, false, false, false, 1)
```
3. **缺少空值判断**:在使用`npc.ui`前应该判断是否创建成功
```lua
if GUI:Win_IsNull(win_newGActive) then
SL:print("窗口创建失败")
return
end
```
## 修正后的代码:
```lua
function npc:openWin()
-- 创造外部界面
local win_newGActive = GUI:Win_Create("win_newGActive", 0, 0, 0, 0, false, false, true, false, false, false, 1)
if GUI:Win_IsNull(win_newGActive) then
SL:print("窗口创建失败")
return
end
GUI:LoadExport(win_newGActive, "newGActive")
npc.ui = GUI:ui_delegate(win_newGActive)
if not npc.ui then
SL:print("UI代理创建失败")
return
end
GUI:addOnClickEvent(npc.ui.esc, function()
GUI:Win_Close(win_newGActive)
end)
-- 修正第29行:移除多余的函数调用
GUI:Timeline_MoveBy(npc.ui.Panel_leftBtn, {x = 400, y = 0}, 0.25, function() end)
GUI:Timeline_MoveBy(npc.ui.Panel_rightText, {x = -900, y = 0}, 0.25, function() end)
local selectBtn = nil
for i = 1, 3 do
local btn = GUI:getChildByName(npc.ui.Panel_leftBtn, "btn_" .. i)
if not GUI:Win_IsNull(btn) then
GUI:addOnClickEvent(btn, function()
if selectBtn and not GUI:Win_IsNull(selectBtn) then
GUI:Button_setTitleColor(selectBtn, "#ffffff")
end
GUI:Button_setTitleColor(btn, "#27ff00")
selectBtn = btn
end)
end
end
end
```
**注意**:`GUI:Timeline_MoveBy`函数在知识库中没有找到,这可能是自定义函数或底层函数。如果这个函数不存在,你需要检查脚本中是否有定义,或者使用其他动画函数替代。
下次写代码时要注意函数调用的正确格式,特别是参数传递和函数调用语法。如果还有问题可以继续问我!
← 返回问答库