这个错误是因为你的`PlayerBaseAtt`模块缺少`UpdateBaseAttri()`函数的实现。从错误堆栈可以看出,代码试图调用一个值为nil的`UpdateBaseAttri`字段。
根据浮生梦老师前端课程内容,你需要添加以下代码到你的`PlayerBaseAtt`模块中:
```lua
PlayerBaseAtt._index = 0 --添加的属性条编号
function PlayerBaseAtt.UpdateBaseAttri()
local list = PlayerBaseAtt._ui.ListView_base
GUI:removeAllChildren(list)
-- 这里需要根据你的实际需求添加属性显示逻辑
-- 例如:
-- for k, v in ipairs(PlayerBaseAtt._baseAttributeStr) do
-- local listData = {
-- str = v,
-- strValue = getAttValue(k)
-- }
-- PlayerBaseAtt.CreateAttri(list, listData)
-- end
end
function PlayerBaseAtt.CreateAttri(parent, data)
PlayerBaseAtt._index = PlayerBaseAtt._index + 1
local widget = GUI:Widget_Create(parent, "Attribute_" .. PlayerBaseAtt._index, 0, 0, 348, 27)
-- 根据平台加载不同的UI文件
if SL:GetMetaValue("IS_PC_PLAY_MODE") then
GUI:LoadExport(widget, "player/att_show_list_win32")
else
GUI:LoadExport(widget, "player/att_show_list")
end
local ui = GUI:ui_delegate(widget)
-- 设置属性名称和值
if ui.Text_attName then
GUI:Text_setString(ui.Text_attName, data.str or "")
end
if ui.Text_attValue then
GUI:Text_setString(ui.Text_attValue, data.strValue or "")
end
return ui
end
```
你还需要在`main`函数的最后添加对`UpdateBaseAttri()`的调用:
```lua
function PlayerBaseAtt.main(data)
-- ... 你现有的main函数代码 ...
PlayerBaseAtt._index = 0 --添加的属性条编号
PlayerBaseAtt.UpdateBaseAttri() -- 添加这行
return true
end
```
注意:你还需要定义`PlayerBaseAtt._baseAttributeStr`这个表,或者在`UpdateBaseAttri()`函数中根据你的需求修改属性显示逻辑。