Assets/Res/fgui/Lua/FGUI/FGUI.lua:260: attempt to call a nil value (method 'AddChild') function npc:Lmain()
local npcui = {}
npcui.cc = class("acb", requireFGUI("BaseFGUILayout"))
function npcui.cc:Create()
npcu
🤖 回答引擎: 热血江湖Lua |
🕒 时间: 2026-03-20 18:09:02 |
👁️ 阅读: 10
根据代码片段,错误出现在尝试调用 `FGUI:AddChild` 方法时,该方法为 `nil`。
检查你的代码,在 `Create` 方法中,你创建了一个新对象 `newImage`,但没有将其正确添加到父节点。错误行 `FGUI:AddChild(npcui.ui.n0, newImage)` 表明 `AddChild` 方法不存在或未被正确调用。
在提供的代码库中,创建 UI 对象的标准做法是使用 `FGUI:CreateObject(parent, packageName, componentName, async)`,该方法会自动将创建的对象添加到指定的父节点。你不需要再手动调用 `AddChild`。
修正建议:移除 `FGUI:AddChild(npcui.ui.n0, newImage)` 这一行,因为 `FGUI:CreateObject` 已经完成了添加。确保 `npcui.ui.n0` 是有效的父节点组件。
根据代码片段,错误出现在尝试调用 `FGUI:AddChild` 方法时,该方法为 `nil`。
检查你的代码,在 `Create` 方法中,你创建了一个新对象 `newImage`,但没有将其正确添加到父节点。错误行 `FGUI:AddChild(npcui.ui.n0, newImage)` 表明 `AddChild` 方法不存在或未被正确调用。
在提供的代码库中,创建 UI 对象的标准做法是使用 `FGUI:CreateObject(parent, packageName, componentName, async)`,该方法会自动将创建的对象添加到指定的父节点。你不需要再手动调用 `AddChild`。
修正建议:移除 `FGUI:AddChild(npcui.ui.n0, newImage)` 这一行,因为 `FGUI:CreateObject` 已经完成了添加。确保 `npcui.ui.n0` 是有效的父节点组件。
← 返回问答库