How to insert all the items in several chests?

Place to get help with not working mods / modding interface.
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

How to insert all the items in several chests?

Post by WIZ4 »

I can not insert on all items in chests. Items that do not fit in the chest, disappear.How to solve this problem?

Code: Select all

  global.items = {}
  global.items.items_list =
  {
	defence =
    {
      ["stone-wall"] = 1000,
      ["gun-turret"] = 500,
      ["uranium-rounds-magazine"] = 1000
    }}

Code: Select all

function advanced_chest()
local chest = game.surfaces.nauvis.create_entity{name = "wooden-chest", position= {game.player.position.x, game.player.position.y+1},force = game.player.force}
for k,list in pairs(global.items.items_list.defence) do
	if chest.can_insert{name=k, count=list} == false then 
	chest = game.surfaces.nauvis.create_entity{name = "wooden-chest", position= {chest.position.x, chest.position.y+1},force = game.player.force}
	end
	chest.insert{name=k, count=list}	
end
end	
Screenshot_8.png
Screenshot_8.png (230.55 KiB) Viewed 1207 times
Screenshot_9.png
Screenshot_9.png (242.68 KiB) Viewed 1207 times
My native language is russian. Sorry if my messages are difficult to read.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to insert all the items in several chests?

Post by eradicator »

http://lua-api.factorio.com/latest/LuaI ... ory.insert
Return value
Number of items actually inserted.
So just substract that number from the list you have. And loop over it for every chest. At the end all the entries in the list should end up being == 0.
Post Reply

Return to “Modding help”