I have some hidden entities that I destroy once the primary entity is destroyed.
Currently I have a radar, and was hoping to add a power pole and a lamp.
I need to make it compatible with existing games so if you already had the entity you won't have any issues.
Below is my code. It works as intended with NEW entities built, but when I remove Existing entities that did not have the new items, the old items are not removed.
In the image below, this was an old item, it only had the Radar, and pole, not the lamp, but when I now remove it those don't get removed.
Code When Building:
Code: Select all
if entity.valid and entity.name == "bi-arboretum-area" then
writeDebug("Arboretum has been built")
local arboretum_new = "bi-arboretum"
local radar_name = "bi-arboretum-radar"
local pole_name = "bi-hidden-power-pole"
local lamp_name = "bi-bio-farm-light"
local create_arboretum = surface.create_entity({name = arboretum_new, position = position, direction = entity.direction, force = force}) -- New Arboretum, the first was just used for Radius overlay
local create_pole = surface.create_entity({name = pole_name, position = position, direction = entity.direction, force = force}) -- Hidden pole
local create_lamp = surface.create_entity({name = lamp_name, position = position, force = force}) -- Hidden Lamp
local position_c = {position.x - 3.5, position.y + 3.5}
local create_radar = surface.create_entity({name = radar_name, position = position_c, direction = entity.direction, force = force}) -- Hidden Radar
create_radar.minable = false
create_radar.destructible = false
create_pole.minable = false
create_pole.destructible = false
create_lamp.minable = false
create_lamp.destructible = false
-- Remove the "Overlay" Entity
event.created_entity.destroy()
-- Group Multiple Entities Together
global.Arboretum_Table[create_arboretum.unit_number] = {inventory=create_arboretum, radar=create_radar, pole=create_pole, lamp=create_lamp}
end
Code: Select all
--- Arboretum has been removed
if entity.valid and entity.name == "bi-arboretum" then
writeDebug("Arboretum has been removed")
if global.Arboretum_Table[entity.unit_number] then
global.Arboretum_Table[entity.unit_number].radar.destroy()
if global.Arboretum_Table[entity.unit_number].pole.valid then
global.Arboretum_Table[entity.unit_number].pole.destroy()
end
if global.Arboretum_Table[entity.unit_number].lamp.valid then
global.Arboretum_Table[entity.unit_number].lamp.destroy()
end
global.Arboretum_Table[entity.unit_number] = nil
end
end
Not sure what to do here.
Again, it works as intended with new Entities, but Existing entities, before the new Items are added is causing an issue.
Thanks.