Fixed selection logic.

This commit is contained in:
Andrew Lalis 2023-04-27 12:59:32 +02:00
parent affd55fa81
commit febe9b8878
1 changed files with 14 additions and 9 deletions

View File

@ -292,22 +292,20 @@ function itemscript.selectRandom(filterExpr)
return true
end
-- Selects a slot containing at least minCount (or 1) of an item type matching
-- Selects a slot containing at least 1 of an item type matching
-- the given filter expression.
function itemscript.selectOrWait(filterExpr, minCount)
minCount = minCount or 1
function itemscript.selectOrWait(filterExpr)
local filter = itemscript.filterize(filterExpr)
while itemscript.totalCount(filter) < minCount do
print("Couldn't find at least " .. minCount .. " item(s) matching the filter expression: \"" .. filterExpr .. "\". Please add it.")
while not itemscript.select(filter) do
print("Couldn't find at least 1 item matching the filter expression: \"" .. filterExpr .. "\". Please add it.")
os.pullEvent("turtle_inventory")
end
end
function itemscript.selectRandomOrWait(filterExpr, minCount)
minCount = minCount or 1
function itemscript.selectRandomOrWait(filterExpr)
local filter = itemscript.filterize(filterExpr)
while itemscript.totalCount(filter) < minCount do
print("Couldn't find at least " .. minCount .. " item(s) matching the filter expression: \"" .. filterExpr .. "\". Please add it.")
while not itemscript.select(filter) do
print("Couldn't find at least 1 item matching the filter expression: \"" .. filterExpr .. "\". Please add it.")
os.pullEvent("turtle_inventory")
end
end
@ -324,6 +322,13 @@ function itemscript.selectEmpty()
return false
end
function itemscript.selectEmptyOrWait()
while not itemscript.selectEmpty() do
print("Couldn't find an empty slot. Please remove some items.")
os.pullEvent("turtle_inventory")
end
end
-- Helper function to drop items in a flexible way, using a drop function and filtering function.
local function dropFiltered(dropFunction, filterExpr)
local filter = itemscript.filterize(filterExpr)