local qiyifahshi = {}
function qiyifahshi.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
qiyifahshi.parent = lib:openwin(param1, nil, true, param4) or {}
根据错误信息显示,问题出现在第65行的 `GUI:setVisible(ui.Button_3, true)` 或 `GUI:setVisible(ui.Button_3, false)` 调用时,`ui.Button_3` 这个控件对象是 `nil`。
在你的代码中,`ui = qiyifahshi.parent._ui`,但 `ui.Button_3` 可能没有在UI布局文件中定义,或者 `GUI:ui_delegate` 没有正确创建这个控件对象。
**错误原因分析:**
1. `ui.Button_3` 控件不存在,但代码中尝试访问它。
2. 在调用 `GUI:setVisible()` 之前,没有检查控件对象是否为有效对象。
**解决方案:**
修改 `qiyifahshi.upmain()` 函数中关于 `Button_3` 和 `Image_1` 的代码部分,在操作控件前先检查对象是否存在且有效。
```lua
function qiyifahshi.upmain()
local var = tonumber(lib:getstr("U32") or 0)
local ui = qiyifahshi.parent._ui
if not GUI:Win_IsNull(ui.Text_1) then
GUI:Text_setString(ui.Text_1, "收集掉落的上古碎片" .. (var or 0) .. "/10个")
end
local completionFlag = tonumber(lib:getstr("U33") or 0)
local isCompleted = (completionFlag == 1)
-- 修改点1:检查 ui.Button_3 是否存在且不为空
if ui.Button_3 and not GUI:Win_IsNull(ui.Button_3) then
if isCompleted then
GUI:setVisible(ui.Button_3, true)
else
GUI:setVisible(ui.Button_3, false)
end
end
-- 修改点2:检查 ui.Image_1 是否存在且不为空
if ui.Image_1 and not GUI:Win_IsNull(ui.Image_1) then
if isCompleted then
GUI:setVisible(ui.Image_1, true)
else
GUI:setVisible(ui.Image_1, false)
end
end
-- 其他代码保持不变...
end
```
**关键修改说明:**
- 将 `if GUI:Win_IsNotNull(ui.Button_3) then` 改为 `if ui.Button_3 and not GUI:Win_IsNull(ui.Button_3) then`
- 同样修改 `Image_1` 的检查逻辑
- 先检查 `ui.Button_3` 对象是否存在(不为 `nil`),再检查它是否是有效的GUI对象
这样修改后,即使 `ui.Button_3` 不存在,代码也不会报错,而是会跳过相关操作。下次写代码时要注意,UI控件名必须和布局文件中的名称完全一致,否则 `GUI:ui_delegate` 返回的 `ui` 表中就不会有这个控件对象。