LUA: 尝试索引本地变量 '' (一个空值)

求助:我正在尝试索引本地变量 firstClipArr (一个 nil 值),但我无论如何都无法解决它。这是代码:

function updateRemoteAmmo( ammoTable )
if not client or getElementData(client,"loggedin") ~= 1 then
    return
end
local items = getItems( client )
local weaponCheck = { }
for _, itemCheck in ipairs( items ) do
    if (itemCheck[1] == 115) then -- 武器项目
        local weaponItemDetails = explode(':', itemCheck[2])
        local weaponAmmoCountValid = 0
        local firstClip = 0
        local firstClipInventorySlot = 0
        local firstClipArr = nil

        for itemCheckBulletsSlot, itemCheckBullets in ipairs( items ) do
            if (itemCheckBullets[1] == 116) then
                local weaponBulletDetails = explode(':', itemCheckBullets[2])
                if tonumber(weaponBulletDetails[1]) == tonumber(weaponItemDetails[1]) then
                    if (firstClip == 0 and tonumber(weaponBulletDetails[2]) > 0) then
                        firstClip =  tonumber(weaponBulletDetails[2])
                        firstClipInventorySlot = itemCheckBulletsSlot
                        firstClipArr = weaponBulletDetails
                    end

                    weaponAmmoCountValid = weaponAmmoCountValid + weaponBulletDetails[2]
                end
            end
        end

        local weaponSyncPacket = false
        for _, tableValue in ipairs(ammoTable) do

            if tonumber(tableValue[1]) == tonumber(weaponItemDetails[1]) then

                weaponSyncPacket = tableValue
            end
        end

        if not weaponSyncPacket then

            return
        end

        local fakebullet = false
        if (getElementData(client, "cf:"..weaponItemDetails[1])) then
            fakebullet = true
            weaponAmmoCountValid = weaponAmmoCountValid + 1
        end

        if (weaponAmmoCountValid > weaponSyncPacket[2]) then -- 用这把枪已经射击过

            local totalBulletsShot = weaponAmmoCountValid - weaponSyncPacket[2]

            local update = updateItemValue(client, firstClipInventorySlot,firstClipArr[1] ..":"..weaponSyncPacket[3]  ..":"..  firstClipArr[3])

            if not update then
                outputDebugString("fail")
            end
            weaponAmmoCountValid = weaponAmmoCountValid - totalBulletsShot
        end

        table.insert(weaponCheck, {weaponItemDetails[1], weaponAmmoCountValid, fakebullet} )
    end
end
点赞