注册 登录
编程论坛 Lua论坛

lua table 排序问题

lvweicheng 发布于 2019-11-28 19:44, 2658 次点击
程序代码:

   
    local function compare(a, b)
        print("b", b)
        if a ~= nil and b ~= nil then
            if tItem_Exp[a[2]] ~= nil and tItem_Exp[b[2]] == nil then
                return true
            elseif tItem_Exp[a[2]] == nil and tItem_Exp[b[2]] ~= nil then
                return false
            elseif tItem_Exp[a[2]] ~= nil and tItem_Exp[b[2]] ~= nil then
                return true
            else
                if a[3] == b[3] then
                    if a[4] == b[4] then
                        return a[5] < b[5]
                    else
                        return tEquip_Color_modulus[a[4]] < tEquip_Color_modulus[b[4]]
                    end
                else
                    return a[3] < b[3]
                end
            end
        else
            return false
        end
    end
    -- print(compare)
    table.sort(ServantWnd.tItem, compare)
只有本站会员才能查看附件,请 登录

这段代码中打印b为什么会出现nil的情况
0 回复
1