Keep inventory after building upgrade

Place to get help with not working mods / modding interface.
MegaMech
Burner Inserter
Burner Inserter
Posts: 12
Joined: Tue Mar 22, 2016 10:02 pm
Contact:

Keep inventory after building upgrade

Post 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
Post Reply

Return to “Modding help”