I need to track built entitys, so i wanted to store them in an array on the entityBuilt event:
Code: Select all
function entityBuilt(event, entity)
local force = entity.force
global.lordofwar.exportWarehouses[force] = global.lordofwar.exportWarehouses[force] or {}
if entity.name == "export-warehouse" then
table.insert(global.lordofwar.exportWarehouses[force],entity)
end
end
Code: Select all
function getInventory(force,goods)
local warehouses = global.lordofwar.exportWarehouses[force]
local itemCount = 0
if warehouses == nil then
game.players[1].print("warehouses is nil!")
return "n/a"
else
game.players[1].print("warehouses is not nil!")
for k,v in pairs(warehouses) do
itemCount = itemCount + warehouses.get_item_count(goods)
end
return itemCount
end
end
what am i not seeing?
thanks
Edit.
It does work when i use force.name instead of force. Well, its solved ...