Fixed selection logic.
This commit is contained in:
parent
affd55fa81
commit
febe9b8878
|
@ -292,22 +292,20 @@ function itemscript.selectRandom(filterExpr)
|
||||||
return true
|
return true
|
||||||
end
|
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.
|
-- the given filter expression.
|
||||||
function itemscript.selectOrWait(filterExpr, minCount)
|
function itemscript.selectOrWait(filterExpr)
|
||||||
minCount = minCount or 1
|
|
||||||
local filter = itemscript.filterize(filterExpr)
|
local filter = itemscript.filterize(filterExpr)
|
||||||
while itemscript.totalCount(filter) < minCount do
|
while not itemscript.select(filter) do
|
||||||
print("Couldn't find at least " .. minCount .. " item(s) matching the filter expression: \"" .. filterExpr .. "\". Please add it.")
|
print("Couldn't find at least 1 item matching the filter expression: \"" .. filterExpr .. "\". Please add it.")
|
||||||
os.pullEvent("turtle_inventory")
|
os.pullEvent("turtle_inventory")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function itemscript.selectRandomOrWait(filterExpr, minCount)
|
function itemscript.selectRandomOrWait(filterExpr)
|
||||||
minCount = minCount or 1
|
|
||||||
local filter = itemscript.filterize(filterExpr)
|
local filter = itemscript.filterize(filterExpr)
|
||||||
while itemscript.totalCount(filter) < minCount do
|
while not itemscript.select(filter) do
|
||||||
print("Couldn't find at least " .. minCount .. " item(s) matching the filter expression: \"" .. filterExpr .. "\". Please add it.")
|
print("Couldn't find at least 1 item matching the filter expression: \"" .. filterExpr .. "\". Please add it.")
|
||||||
os.pullEvent("turtle_inventory")
|
os.pullEvent("turtle_inventory")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -324,6 +322,13 @@ function itemscript.selectEmpty()
|
||||||
return false
|
return false
|
||||||
end
|
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.
|
-- Helper function to drop items in a flexible way, using a drop function and filtering function.
|
||||||
local function dropFiltered(dropFunction, filterExpr)
|
local function dropFiltered(dropFunction, filterExpr)
|
||||||
local filter = itemscript.filterize(filterExpr)
|
local filter = itemscript.filterize(filterExpr)
|
||||||
|
|
Loading…
Reference in New Issue