Page 1 of 1

let ghost.revive() return list of LuaItemStack

Posted: Thu Nov 10, 2016 10:22 am
by gheift
Currently if you revive a ghost with ghost.revive() you get a dictionary of items which layed under the ghost. If there layed a blueprint, gun ammo or armor, you are not able to preserve properties like the blueprint content, grid content, health, ammo or durability (only the ones I could think of).

If there lays two chests items with health of 50% and 75% under a ghost and it is revived, what I currently get is the following:

Code: Select all

local items, entity = ghost.revive()
-- items = {"chest" = 2}
What I want to get is the following:

Code: Select all

local items, entity = ghost.revive()
-- list of LuaItemStack
-- items = {{name = "chest", health = 0.5, …}, {name = "chest", health = 0.75, …}
Thanks,
Gerhard

Re: let ghost.revive() return list of LuaItemStack

Posted: Thu Nov 10, 2016 4:48 pm
by Rseding91
It returns the dictionary because there's nothing that can own the item stacks anymore. Something on the C++ side has to own the item stack for a LuaItemStack to point at it and after you've revived the entity there's nobody to own them and as such they're deleted after the function call returns.

Re: let ghost.revive() return list of LuaItemStack

Posted: Thu Nov 10, 2016 9:36 pm
by gheift
OK, I understand, memory management is the problem.
Is there another reliable way to get the ItemStacks before reviving the ghost?
The one I am thinking of is:

Code: Select all

-- area = ghost.position extended by ghost.ghost_ptototype.collision_box extended by item_on_ground_prototype.collision_box
items = surface.find_entities_filtered{area = area, name = 'item-on-ground'}