Page 1 of 1

let inventory.insert() accept more properties

Posted: Thu Nov 10, 2016 10:36 am
by gheift
Currently, the inventory.insert(items) only accept following properties
  • name
  • count
  • health
I would like you to add the following properties:
  • durability, for e.g. tools and repair-kits
  • ammo, for left rounds in e.g. firearm-magazines
Additionally if the passed argument is a LuaItemStack and the item in this stack contains a blueprint, book, grid or other complex properties then insert the items with all its properties to the new inventory. Currently if I pass a LuaItemStack with a full blueprint and I use it in inventory.insert(stack_with_blueprint) it inserts an empty blueprint in the inventory.

Thanks,
Gerhard

Re: let inventory.insert() accept more properties

Posted: Thu Nov 10, 2016 12:11 pm
by Klonan
You can use LuaItemStack.set_stack to achieve the same functionality,
Insert is meant to be a simple way of inserting items to an entity,
LuaItemstack contains more powerful functions, and should be used if you want to do anything more complex
http://lua-api.factorio.com/latest/LuaItemStack.html

Re: let inventory.insert() accept more properties

Posted: Thu Nov 10, 2016 1:10 pm
by gheift
I am aware of LuaItemStack.set_stack, but the problem is the following: lets say I want to add a firearm-magazine with 16 ammo left → count = 2, ammo = 6 to an inventory. To do so I have to either find a free ItemStack in the inventory, set the stack or if no slot is free, search for a stack with firearm-magazines and add them there by manually add the ammo and check for overflow. The same procedure must be done for tools and repair packs. The handling of entites with grids, blueprints or books is even more complicated. Perhaps a better solution would be exposing a function like this:

Code: Select all

local leftover = inventory.add_stack(itemstack)
  • itemstack is not modified
  • leftover is a stack with items, which could not be added to the inventory
if only 8 rounds fit into the inventory, and an itemstack countains 6, then I would like this to behave like this:

Code: Select all

local itemstack = {name = "firearm-magazine", count = 2, ammo = 6}
local leftover = inventory.add_stack(itemstack)
-- leftover = {name = "firearm-magazine", count = 1, ammo = 8}
A function like this should be available internal for handling the CTRL-Click of the mouse-stack to entities like chests, assemblers etc.

Re: let inventory.insert() accept more properties

Posted: Tue Nov 29, 2016 11:50 pm
by Rseding91
Added for 0.15.

Re: let inventory.insert() accept more properties

Posted: Wed Nov 30, 2016 2:40 am
by Mooncat
Rseding91 wrote:Added for 0.15.
It is amazing to see you are implementing requests that have been made some time ago. Thanks a lot! :D