Skip to content

WarehouseM在可用容器为空时报错 #21

Description

@54679128

观察这段WarehouseM代码:

for rType, ticket in pairs(ticketPackage) do -- 注意,有些模组的容器(精妙存储系列)会在没有安装储罐升级的情况下提供通用流体外设方法
            if not storage[rType] then
                ticketPackage[rType] = nil
                goto continue
            end
            log.trace(("Pick random storage in type: %s"):format(tostring(rType)))
            local randomIndex = math.random(#storage[rType])
            local randomStorage = storage[rType][randomIndex] -- 随机选一个存储容器
            success = ticket:use(randomStorage.peripheralName)
            log.trace(("Try use ticket: %s, result: %s"):format(tostring(ticket), tostring(success)))
            if not success then
                table.remove(storage[rType], randomIndex)
            end
            ::continue::
        end

发现math.random(#storage[rType])会在仓库内没有任何可以存储该资源类型的容器时报错:“bad argument #1 (interval is empty)”。这应该可以通过预先检查避免。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions