fix: fix startup logic

Previous: if a KEEP_STOCKED material was between lower and upper, it would
sit there on startup, regardless of whether material was needed in export.

New logic is that materials between the lower and upper bound will try to
export until the lower bound is reached on startup.
This commit is contained in:
Emerson Rosen-Jones 2026-01-17 19:02:39 -05:00
parent 4e2fdccc49
commit e82591297c

View file

@ -200,7 +200,7 @@ function createModes (items)
return result
end
function updateModes (current_modes, current_stock)
function updateModes (current_modes, current_stock, first_run)
local lower_lim, upper_lim
local limits = {}
for item, _ in pairs(current_modes) do
@ -221,7 +221,7 @@ function updateModes (current_modes, current_stock)
if count == nil then count = 0 end
if count <= limits.lower then
current_modes[item] = {"recipe"}
elseif count >= limits.upper then
elseif count >= limits.upper or first_run then
current_modes[item] = {
"export",
count - limits.lower,
@ -324,14 +324,14 @@ function export (ticker, item, amt)
ticker.requestFiltered(EXPORT_ADDR, request)
end
function run (ticker, export_storage, current_modes)
function run (ticker, export_storage, current_modes, first_run)
if SPEEDOMETER ~= "" and peripheral.call(SPEEDOMETER, "getSpeed") == 0 then
os.sleep(SLEEP_T)
return run (ticker, export_storage, current_modes)
return run (ticker, export_storage, current_modes, first_run)
end
local export_amounts = getAmounts(export_storage.list)
local stock_amounts = getAmounts(ticker.stock)
updateModes(current_modes, stock_amounts)
updateModes(current_modes, stock_amounts, first_run)
for item, mode in pairs(current_modes) do
-- mode[1] is mode, mode[2] is amt_extra when exporting
if mode[1] == "recipe" then
@ -355,5 +355,5 @@ if arg ~= nil and arg[1] == "run" then
local ticker = peripheral.wrap(STOCK_TICKER)
local export_storage = peripheral.wrap(EXPORT_STORAGE)
local current_modes = createModes(KEEP_STOCKED)
run(ticker, export_storage, current_modes)
run(ticker, export_storage, current_modes, true)
end