let ghost.revive() return list of LuaItemStack

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
gheift
Fast Inserter
Fast Inserter
Posts: 188
Joined: Tue Mar 03, 2015 9:20 pm
Contact:

let ghost.revive() return list of LuaItemStack

Post 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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13246
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.

gheift
Fast Inserter
Fast Inserter
Posts: 188
Joined: Tue Mar 03, 2015 9:20 pm
Contact:

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

Post 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'}

Post Reply

Return to “Modding interface requests”