[solved] use force.name instead of force

Place to get help with not working mods / modding interface.
Post Reply
safan
Fast Inserter
Fast Inserter
Posts: 126
Joined: Mon Dec 23, 2013 7:26 pm
Contact:

[solved] use force.name instead of force

Post 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 ...
Last edited by safan on Sun Aug 14, 2016 9:01 am, edited 1 time in total.

keyboardhack
Filter Inserter
Filter Inserter
Posts: 478
Joined: Sat Aug 23, 2014 11:43 pm
Contact:

Re: snippet of code doesnt work

Post by keyboardhack »

Could you post all the code or the mod itself? Would make it easier to debug.
Waste of bytes : P

Post Reply

Return to “Modding help”