Looking for event (destroyed entities)
Posted: Thu May 14, 2020 12:38 pm
I've received a bug report yesterday because of a crash that involved accessing an invalid entity. The bug report was a case of landfill accidentally placed over an entity on water, but the same thing also happened when waterfill is placed over an entity on land.
I want to react to entities disappearing, but I haven't found a proper event yet. They are not mined, so neither on_X_pre_mined nor on_X_mined_entity trigger. The entities also don't die, so they also don't trigger on_entity_died or script_raised_destroy. Is there an easy way to check for entities that have simply disappeared?
I suppose the entities vanish because their collision mask isn't compatible with that of the placed tile. So I probably could react to on_X_built_tile. But this only triggers after a tile has been placed, and it doesn't return the entities that were at that position. I will get the position, so I could loop over the list of stored entities to get their position (except the entities don't exist anymore, so I'd get a "trying to index nil" error). Listening to on_put_item, checking if the item has a placed_as_tile result, checking the collision mask of the tile, looking for entities in that position, and comparing their collision mask with that of the tile could work -- but it's a lot of work, and landfill is usually placed en masse, so that wouldn't be UPS friendly. Does anybody have a better idea?
I want to react to entities disappearing, but I haven't found a proper event yet. They are not mined, so neither on_X_pre_mined nor on_X_mined_entity trigger. The entities also don't die, so they also don't trigger on_entity_died or script_raised_destroy. Is there an easy way to check for entities that have simply disappeared?
I suppose the entities vanish because their collision mask isn't compatible with that of the placed tile. So I probably could react to on_X_built_tile. But this only triggers after a tile has been placed, and it doesn't return the entities that were at that position. I will get the position, so I could loop over the list of stored entities to get their position (except the entities don't exist anymore, so I'd get a "trying to index nil" error). Listening to on_put_item, checking if the item has a placed_as_tile result, checking the collision mask of the tile, looking for entities in that position, and comparing their collision mask with that of the tile could work -- but it's a lot of work, and landfill is usually placed en masse, so that wouldn't be UPS friendly. Does anybody have a better idea?