Jump to content

Trouble with tables


Recommended Posts

Oh that's right, you need to remove the items when you add them to a bundle.

local function SpawnBundle(inst)
    local items = {}
    for i, v in ipairs(inst.stored_items) do
    	local spawned_item =  SpawnSaveRecord(v)
        table.insert(items, spawned_item)
    end

    local bundle = SpawnPrefab("bundle")
    bundle.components.unwrappable:WrapItems(items)
    inst.components.inventory:GiveItem(bundle)
  for i,v in ipairs(items) do
    	v:Remove()
    end
end

This can also be seen in the bundle from the hermitcrab:

local function createbundle(inst,gifts)
    local final = {}
    if #gifts >0 then
        local pouch = SpawnPrefab("hermit_bundle")
        local prize_items = {}
        for _, p in ipairs(gifts) do
            table.insert(prize_items, SpawnPrefab(p))
        end
        pouch.components.unwrappable:WrapItems(prize_items)
		for i, v in ipairs(prize_items) do
			v:Remove()
		end
        table.insert(final,pouch)
    end

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...