Page 1 of 1

[solved] use force.name instead of force

Posted: Sun Aug 14, 2016 6:20 am
by safan
No idea if it's factorio related or a programming error (i'm not a programmer)
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
But apparently its wrong since the following snippet

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
always returns n/a as warehouses is nil
what am i not seeing?

thanks

Edit.
It does work when i use force.name instead of force. Well, its solved ...

Re: snippet of code doesnt work

Posted: Sun Aug 14, 2016 7:31 am
by keyboardhack
Could you post all the code or the mod itself? Would make it easier to debug.