参数变成了空值。

当我在游戏中时,出现了以下错误:

...Addons\WatcherEx\GeminiSpellBook\GeminiSpellBook.lua:91: attempt to index local 'spell' (a nil value)
stack trace:
    ...Addons\WatcherEx\GeminiSpellBook\GeminiSpellBook.lua:91: in function 'IsStance'
    ...Addons\WatcherEx\GeminiSpellBook\GeminiSpellBook.lua:132: in function 'GetInnates'
    ...aming\NCSOFT\WildStar\Addons\WatcherEx\WatcherEx.lua:1868: in function 'UpdateSkillsList'
    ...aming\NCSOFT\WildStar\Addons\WatcherEx\WatcherEx.lua:1606: in function <...aming\NCSOFT\WildStar\Addons\WatcherEx\WatcherEx.lua:1600>

因此,我同时使用以下两个函数:

-描述:确定给定的法术ID是否是姿态。
--参数:- spell:我们需要检查的来自游戏的法术对象。
--返回:-如果ID是姿态法术的ID,则为true;否则为false

function GeminiSpellBook:IsStance(spell)
    for i,group in ipairs(ctClassStancesAbilities) do
        for j, stanceId in pairs(group) do
            if spell:GetId() == stanceId then
                return true
            end
        end
    end

    return false
end

它由以下函数调用:

-描述:获取当前正在播放的角色的所有固有能力并将其存储在内部tInnates结构中。
-函数不需要任何参数,但需要“self”参数,因此
应该作为SpellBook:GetInnates()调用
--参数:
--返回:-固有能力列表。
function GeminiSpellBook:GetInnates()
    If self.tInnates == nil or #self.tInnates <= 0 then
        self.tInnates = { }
        local tSpells = GameLib.GetClassInnateAbilitySpells().tSpells or { }

        For _,spell in ipairs(tSpells) do
            if spell ~= nil and not self.IsStance(spell) then
                table.insert(self.tInnates, spell)
            end
        end
    end

    返回self.innates
end

我已经添加了一个检查来查看是否传递了nill值,但我仍然无法解决这个错误。 我理解的方法是,在函数调用期间传递的参数变成了nil。

但是,当我检查控制台中的数据时,数据确实存在。

点赞
用户1442917
用户1442917

你应该将调用从self.IsStance(spell)修改为self:IsStance(spell) 或者使用self.IsStance(self, spell)。由于你定义IsStance为一个方法(使用GeminiSpellBook:IsStance),它会将第一个参数作为self,这就是spell的赋值位置,而你期望的spell参数得到了nil值,这就是你看到的错误的原因。

2015-02-28 16:51:29