entity not destroyed by entity.destroy
Posted: Sun Aug 03, 2025 11:57 pm
I have an entity which is placed by lua script when placing a different entity, both of which are recorded in a table by unit number. When the first is mined by the player destroy is called on the second, but the entity isn't removed.
Called from the on_player_mined_entity event,
As far as I can tell energy_control is removed ,but the entity is not removed
Does getting an entity by unit number not give you the "real" entity where destroy is concerned?
Called from the on_player_mined_entity event,
Code: Select all
function unregister_hab (event)
for i in pairs (storage.hab_index) do
if storage.hab_index [i] == event.entity.unit_number then
table.remove(storage.hab_index,i)--removing the primary entity from the index table
local energy_control = game.get_entity_by_unit_number(storage.hab_energy_control[i]) -- getting the second by unit number
if energy_control.valid then
energy_control.destroy()
end
table.remove(storage.hab_energy_control,i)--removing the second entity from the index table
end
end
end