[LUA-print] ----------------------------------------
Warning: cc.Node:runAction argument 2 is invalid native object(nullptr)
[LUA-print] ----------------------------------------
[LUA-print] LUA ERROR: ASSERT FAILED ON LUA EXECUTE: Argument must be no
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-27 21:24:02 |
👁️ 阅读: 17
根据错误信息,问题出在第108行的 `GUI:runAction(npc.ui[panelName], moveAction_Up)` 这一句。错误提示 `Argument must be non-nil` 意味着你传递给 `runAction` 的第二个参数(即 `moveAction_Up` 或 `moveAction_Down` 这个动作对象)是 `nil`(空值)。
从你的代码逻辑来看,`moveAction_Up` 和 `moveAction_Down` 是由 `GUI:ActionSequence` 创建的。当 `GUI:ActionSequence` 的某个子动作(比如 `moveActionUp_1`, `moveActionDown_1` 等)创建失败或本身为 `nil` 时,整个序列动作就会是 `nil`。
**问题核心在于:`GUI:ActionMoveTo` 这个函数创建的动作对象为 `nil` 了。**
根据浮生梦老师前端课程内容,`GUI:ActionMoveTo` 函数需要正确的参数才能创建有效的动作对象。请检查以下几点:
1. **确认 `GUI:ActionMoveTo` 函数存在且参数正确**。根据课程案例,其标准用法是:
```lua
local action = GUI:ActionMoveTo(时间, 目标X坐标, 目标Y坐标)
```
你的代码中 `GUI:ActionMoveTo(0.25, 0, 35)` 在语法上是正确的。问题可能出在函数本身不可用。
2. **检查 `GUI:ActionSequence` 的输入**。确保传入序列的所有动作都不是 `nil`。可以在创建后立即打印检查:
```lua
local moveActionUp_1 = GUI:ActionMoveTo(0.25, 0, 35)
SL:print("moveActionUp_1 是否为 nil: ", moveActionUp_1 == nil)
local moveActionDown_1 = GUI:ActionMoveTo(0.15, 0, 0)
SL:print("moveActionDown_1 是否为 nil: ", moveActionDown_1 == nil)
local moveAction_Up = GUI:ActionSequence(moveActionUp_1, moveActionDown_1)
SL:print("moveAction_Up 是否为 nil: ", moveAction_Up == nil)
```
如果打印结果显示为 `nil`,则证明 `GUI:ActionMoveTo` 在当前环境下未能成功创建动作。
**解决方案(基于现有知识库的替代方案):**
既然 `GUI:ActionMoveTo` 可能不可用,我们可以使用课程中明确存在的 `GUI:Timeline_MoveTo` 函数来替代平移动画。你在代码的其他部分已经成功使用了它。
修改你的向上平移按钮回调函数如下:
```lua
GUI:addOnClickEvent(npc.ui.jobBut_1, function()
GUI:setEnabled(npc.ui.jobBut_1, false)
GUI:setEnabled(npc.ui.jobBut_2, false)
if a == 1 then
a = 2
GUI:Timeline_MoveTo(npc.ui.Panel_1, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_3, {x = 5, y = -316}, 0, function() end)
elseif a == 2 then
a = 3
GUI:Timeline_MoveTo(npc.ui.Panel_2, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_1, {x = 5, y = -316}, 0, function() end)
else
a = 1
GUI:Timeline_MoveTo(npc.ui.Panel_3, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_2, {x = 5, y = -316}, 0, function() end)
end
local panelName = "Panel_" .. a
-- 使用 Timeline_MoveTo 替代 runAction 和 ActionMoveTo
-- 先移动到偏移位置,再移回,模拟弹跳效果
GUI:Timeline_MoveTo(npc.ui[panelName], {x = 0, y = 35}, 0.25, function()
GUI:Timeline_MoveTo(npc.ui[panelName], {x = 0, y = 0}, 0.15, function()
-- 动画完成后恢复按钮点击
GUI:setEnabled(npc.ui.jobBut_1, true)
GUI:setEnabled(npc.ui.jobBut_2, true)
end)
end)
end)
```
对向下平移的按钮回调也做类似修改,将 `runAction` 部分替换为嵌套的 `GUI:Timeline_MoveTo` 调用。
**总结:**
错误是由于 `GUI:ActionMoveTo` 返回了 `nil` 动作对象导致的。在996引擎的某些版本或配置下,直接的动作创建函数可能不稳定。优先使用你代码中已经验证可用的 `GUI:Timeline_MoveTo` 函数来实现动画,它是更可靠的选择。下次遇到类似问题,记得先检查基础函数(如 `ActionMoveTo`, `ActionScaleTo` 等)的返回值是否为 `nil`。
根据错误信息,问题出在第108行的 `GUI:runAction(npc.ui[panelName], moveAction_Up)` 这一句。错误提示 `Argument must be non-nil` 意味着你传递给 `runAction` 的第二个参数(即 `moveAction_Up` 或 `moveAction_Down` 这个动作对象)是 `nil`(空值)。
从你的代码逻辑来看,`moveAction_Up` 和 `moveAction_Down` 是由 `GUI:ActionSequence` 创建的。当 `GUI:ActionSequence` 的某个子动作(比如 `moveActionUp_1`, `moveActionDown_1` 等)创建失败或本身为 `nil` 时,整个序列动作就会是 `nil`。
**问题核心在于:`GUI:ActionMoveTo` 这个函数创建的动作对象为 `nil` 了。**
根据浮生梦老师前端课程内容,`GUI:ActionMoveTo` 函数需要正确的参数才能创建有效的动作对象。请检查以下几点:
1. **确认 `GUI:ActionMoveTo` 函数存在且参数正确**。根据课程案例,其标准用法是:
```lua
local action = GUI:ActionMoveTo(时间, 目标X坐标, 目标Y坐标)
```
你的代码中 `GUI:ActionMoveTo(0.25, 0, 35)` 在语法上是正确的。问题可能出在函数本身不可用。
2. **检查 `GUI:ActionSequence` 的输入**。确保传入序列的所有动作都不是 `nil`。可以在创建后立即打印检查:
```lua
local moveActionUp_1 = GUI:ActionMoveTo(0.25, 0, 35)
SL:print("moveActionUp_1 是否为 nil: ", moveActionUp_1 == nil)
local moveActionDown_1 = GUI:ActionMoveTo(0.15, 0, 0)
SL:print("moveActionDown_1 是否为 nil: ", moveActionDown_1 == nil)
local moveAction_Up = GUI:ActionSequence(moveActionUp_1, moveActionDown_1)
SL:print("moveAction_Up 是否为 nil: ", moveAction_Up == nil)
```
如果打印结果显示为 `nil`,则证明 `GUI:ActionMoveTo` 在当前环境下未能成功创建动作。
**解决方案(基于现有知识库的替代方案):**
既然 `GUI:ActionMoveTo` 可能不可用,我们可以使用课程中明确存在的 `GUI:Timeline_MoveTo` 函数来替代平移动画。你在代码的其他部分已经成功使用了它。
修改你的向上平移按钮回调函数如下:
```lua
GUI:addOnClickEvent(npc.ui.jobBut_1, function()
GUI:setEnabled(npc.ui.jobBut_1, false)
GUI:setEnabled(npc.ui.jobBut_2, false)
if a == 1 then
a = 2
GUI:Timeline_MoveTo(npc.ui.Panel_1, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_3, {x = 5, y = -316}, 0, function() end)
elseif a == 2 then
a = 3
GUI:Timeline_MoveTo(npc.ui.Panel_2, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_1, {x = 5, y = -316}, 0, function() end)
else
a = 1
GUI:Timeline_MoveTo(npc.ui.Panel_3, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_2, {x = 5, y = -316}, 0, function() end)
end
local panelName = "Panel_" .. a
-- 使用 Timeline_MoveTo 替代 runAction 和 ActionMoveTo
-- 先移动到偏移位置,再移回,模拟弹跳效果
GUI:Timeline_MoveTo(npc.ui[panelName], {x = 0, y = 35}, 0.25, function()
GUI:Timeline_MoveTo(npc.ui[panelName], {x = 0, y = 0}, 0.15, function()
-- 动画完成后恢复按钮点击
GUI:setEnabled(npc.ui.jobBut_1, true)
GUI:setEnabled(npc.ui.jobBut_2, true)
end)
end)
end)
```
对向下平移的按钮回调也做类似修改,将 `runAction` 部分替换为嵌套的 `GUI:Timeline_MoveTo` 调用。
**总结:**
错误是由于 `GUI:ActionMoveTo` 返回了 `nil` 动作对象导致的。在996引擎的某些版本或配置下,直接的动作创建函数可能不稳定。优先使用你代码中已经验证可用的 `GUI:Timeline_MoveTo` 函数来实现动画,它是更可靠的选择。下次遇到类似问题,记得先检查基础函数(如 `ActionMoveTo`, `ActionScaleTo` 等)的返回值是否为 `nil`。
← 返回问答库