I used get_contents() on the inventory of the source chest and insert(item) on the inventory of the target chest, which worked. This approach copies the chest item-by-item, meaning it "sorts" the contents into the target chest.
I would like to keep the order of item stacks in the chest. so I tried using the [] operator to access the slots directly and copy the chest slot-by-slot but this fails, although the [] operator is marked Read-Write in the API documentation.
Getting the contents of slot 1
Code: Select all
/c game.player.print(game.player.selected.get_inventory(defines.inventory.chest)[1].name.." "..game.player.selected.get_inventory(defines.inventory.chest)[1].count)
but setting the contents of slot 1 on the same chest
Code: Select all
/c game.player.selected.get_inventory(defines.inventory.chest)[1] = {name="steel-plate", count=10}
Cannot execute command. Error: [string "game.player.selected.get_inventory(defines.in..."]:1: LuaInventory doesn't contain key 1.
What am I doing wrong here?