Make errors from IO be properly printed
This commit is contained in:
parent
b72644dc5f
commit
c360c72f83
65
IO.lua
65
IO.lua
@ -18,39 +18,44 @@ local function get_num_stacks(total_items)
|
|||||||
return math.ceil(total_items / 64)
|
return math.ceil(total_items / 64)
|
||||||
end
|
end
|
||||||
|
|
||||||
while true do
|
local function main()
|
||||||
local stacks_stored = d.map(d.filter(chest.list(), function(x) return x ~= nil end), w.to_wyvern_item)
|
while true do
|
||||||
local items_stored = w.collate_stacks(stacks_stored)
|
local stacks_stored = d.map(d.filter(chest.list(), function(x) return x ~= nil end), w.to_wyvern_item)
|
||||||
|
local items_stored = w.collate_stacks(stacks_stored)
|
||||||
|
|
||||||
local function get_item_count(ii)
|
local function get_item_count(ii)
|
||||||
return (items_stored[ii] or {count = 0}).count
|
return (items_stored[ii] or {count = 0}).count
|
||||||
end
|
|
||||||
|
|
||||||
for item_name, quantity_desired in pairs(conf.items) do
|
|
||||||
local quantity_stocked = get_item_count(item_name)
|
|
||||||
if quantity_desired > quantity_stocked then -- if we have fewer items than are desired, extract some from store
|
|
||||||
local request = w.string_to_item(item_name)
|
|
||||||
request.type = "extract"
|
|
||||||
request.destination_inventory = conf.chest
|
|
||||||
local result = w.unwrap(w.query_by_type("storage", request), "extracting items")
|
|
||||||
print("Moved", result.moved, item_name, "from storage.")
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for slot, item in pairs(stacks_stored) do
|
for item_name, quantity_desired in pairs(conf.items) do
|
||||||
local ii = w.get_internal_identifier(item)
|
local quantity_stocked = get_item_count(item_name)
|
||||||
local stored = get_item_count(ii)
|
if quantity_desired > quantity_stocked then -- if we have fewer items than are desired, extract some from store
|
||||||
local wanted = 0
|
local request = w.string_to_item(item_name)
|
||||||
if conf.items[ii] then wanted = conf.items[ii] + 1 end
|
request.type = "extract"
|
||||||
if (get_num_stacks(stored) * 64) >= wanted then -- if item is not in want list or we have too many, send it back to storage
|
request.destination_inventory = conf.chest
|
||||||
local result = w.unwrap(w.query_by_type("storage", {
|
local result = w.unwrap(w.query_by_type("storage", request), "extracting items")
|
||||||
type = "insert",
|
print("Moved", result.moved, item_name, "from storage.")
|
||||||
from_inventory = conf.chest,
|
end
|
||||||
from_slot = slot
|
|
||||||
}), "inserting items")
|
|
||||||
print("Moved", result.moved, ii, "to storage.")
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
sleep(conf.sleep_time)
|
for slot, item in pairs(stacks_stored) do
|
||||||
|
local ii = w.get_internal_identifier(item)
|
||||||
|
local stored = get_item_count(ii)
|
||||||
|
local wanted = 0
|
||||||
|
if conf.items[ii] then wanted = conf.items[ii] + 1 end
|
||||||
|
if (get_num_stacks(stored) * 64) >= wanted then -- if item is not in want list or we have too many, send it back to storage
|
||||||
|
local result = w.unwrap(w.query_by_type("storage", {
|
||||||
|
type = "insert",
|
||||||
|
from_inventory = conf.chest,
|
||||||
|
from_slot = slot
|
||||||
|
}), "inserting items")
|
||||||
|
print("Moved", result.moved, ii, "to storage.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sleep(conf.sleep_time)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local ok, err = pcall(main)
|
||||||
|
print(w.errors.format(err))
|
Loading…
x
Reference in New Issue
Block a user