since i wanted to make sure i can't go over containter capacity i used LuaInventory::insert(item) function
strangely it seems this function doesn't replicate item completely.
to be precise, let's say you have in your inventory tank, or buggy, or power armor - all these things have own inventories, but when you try to insert them to chest, you get "empty" copy instead.
therefore i checked difference and death chest use
LuaInventory[index]::set_stack(item) function and this one indeed properly works (eg. item is set to container, including it's own inventory)
so my question is rather to authors of API, does insert create new item from "template", instead of doing carbon copy (which i expect set_stack does, unless set_stack assigns reference)
i will give sample codes - player and savechest are obviously source and target entity, there is somewhat complex enumcode for that
this code copies inventory of vehicles, armors and so on (if you put them in your pocket)
Code: Select all
local playerinventory = player.get_inventory(defines.inventory.player_main)
local chestinventory = savechest.get_inventory(defines.inventory.chest)
local chestitems = 1
for j = 1, #playerinventory, 1 do
if playerinventory[j].valid and playerinventory[j].valid_for_read then
local item = playerinventory[j]
local item = playerinventory[j]
if chestinventory.can_insert(item) then
chestitems = chestitems + 1
chestinventory[chestitems].set_stack(item)
end
end
end
Code: Select all
local playerinventory = player.get_inventory(defines.inventory.player_main)
local chestinventory = savechest.get_inventory(defines.inventory.chest)
for j = 1, #playerinventory, 1 do
if playerinventory[j].valid and playerinventory[j].valid_for_read then
local item = playerinventory[j]
local item = playerinventory[j]
if chestinventory.can_insert(item) then
chestinventory.insert(item)
end
end
end