Page 1 of 1

Keep inventory after building upgrade

Posted: Mon Dec 16, 2019 8:20 pm
by MegaMech
Hello,

I am replacing a turret with a fast_replace upgraded one. How do I keep the previous inventory after the upgrade? It says table expected got nil.

Code: Select all

local inv = turret.get_inventory(defines.inventory.turret_ammo).get_contents()
local turret = player.opened --(LuaEntity)
local upg = turret.surface.create_entity { ... }
Things I've tried:

Code: Select all

upg.get_inventory(defines.inventory.turret_ammo).insert(inv[1])
upg.get_inventory(defines.inventory.turret_ammo).insert({name=inv[1], count=inv[1][1]})
upg.get_inventory(defines.inventory.turret_ammo).insert(inv)
upg.insert({name=inv[1], count=inv[1][1]})
upg.insert(inv)
Thanks