fix(inferium-harvester): add sizeof util to compute the size of a table
This commit is contained in:
parent
586b656fd7
commit
997fe76fd1
@ -27,6 +27,18 @@ local localPlan = nil
|
||||
|
||||
-- UTILS
|
||||
|
||||
local function sizeof(t)
|
||||
if not t then
|
||||
return 0
|
||||
end
|
||||
|
||||
local size = 0
|
||||
for k,v in pairs(t) do
|
||||
size = size + 1
|
||||
end
|
||||
return size
|
||||
end
|
||||
|
||||
local function difference(a, b)
|
||||
local aa = {}
|
||||
|
||||
@ -419,15 +431,15 @@ local function replantProcedure()
|
||||
local seedsToRemove = difference(localPlan, remotePlan)
|
||||
local seedsToPlant = difference(remotePlan, localPlan)
|
||||
|
||||
if #seedsToRemove > 0 then
|
||||
print('nb seeds to remove: ' .. #seedsToRemove)
|
||||
if sizeof(seedsToRemove) > 0 then
|
||||
print('nb seeds to remove: ' .. sizeof(seedsToRemove))
|
||||
removeSeeds(seedsToRemove)
|
||||
else
|
||||
print('no seeds to remove')
|
||||
end
|
||||
|
||||
if #seedsToPlant > 0 then
|
||||
print('nb seeds to plants: ' .. #seedsToPlant)
|
||||
if sizeof(seedsToPlant) > 0 then
|
||||
print('nb seeds to plants: ' .. sizeof(seedsToPlant))
|
||||
retrieveSeeds(seedsToPlant)
|
||||
replantSeeds()
|
||||
else
|
||||
|
||||
Loading…
Reference in New Issue
Block a user