[string "GUILayout/NPC/moshenyuanli.lua"]:280: attempt to concatenate a nil value
local function createEntryAnimation()
if not moshenyuanli.parent or not moshenyuanli.parent._ui then
SL:print("界面未初始化,无法创建动画")
return
end
错误在第280行,`string.match(tostring(widget), "Text_(%d)")` 返回了 `nil`,导致字符串拼接失败。
问题分析:
1. 你的 `widget` 变量可能不是真正的控件对象,`tostring(widget)` 无法得到 "Text_1" 这样的字符串
2. 使用 `string.match` 提取数字的方法不可靠
解决方案:
```lua
-- 修改这部分代码
for _, animInfo in ipairs(textAnims) do
local widget = animInfo.widget
-- 错误方式:string.match(tostring(widget), "Text_(%d)")
-- 正确方式:直接使用已知的控件名称
local name = nil
if widget == widgets.text1 then
name = "text1"
elseif widget == widgets.text2 then
name = "text2"
elseif widget == widgets.text3 then
name = "text3"
elseif widget == widgets.text4 then
name = "text4"
end
if widget and not GUI:Win_IsNull(widget) and name and originalPositions[name] then
local pos = originalPositions[name]
table.insert(actionList, GUI:DelayTime(animInfo.delay))
table.insert(actionList, GUI:CallFunc(function()
GUI:runAction(widget, GUI:ActionMoveTo(animInfo.duration, pos.x, pos.y))
end))
end
end
```
或者更简单的方式,直接在 `textAnims` 中指定名称:
```lua
local textAnims = {
{widget = widgets.text1, name = "text1", delay = 0.1, duration = 0.4},
{widget = widgets.text2, name = "text2", delay = 0.2, duration = 0.4},
{widget = widgets.text3, name = "text3", delay = 0.3, duration = 0.4},
{widget = widgets.text4, name = "text4", delay = 0.4, duration = 0.4}
}
for _, animInfo in ipairs(textAnims) do
local widget = animInfo.widget
local name = animInfo.name
if widget and not GUI:Win_IsNull(widget) and originalPositions[name] then
local pos = originalPositions[name]
table.insert(actionList, GUI:DelayTime(animInfo.delay))
table.insert(actionList, GUI:CallFunc(function()
GUI:runAction(widget, GUI:ActionMoveTo(animInfo.duration, pos.x, pos.y))
end))
end
end
```
**注意**:在996引擎中,控件对象转换为字符串不一定能得到控件的名称,应该使用已知的变量名或通过其他方式获取控件名称。