Just a quick question, I have the below function for checking whether or not an entity that resides in a specific type has power or not.
The function of this is that, if this entity doesn't have power, it explodes.
Code: Select all
function check_power(event)
-- Check every second --
if event.tick % 60 == 0 then
-- Loop the surfaces to find all of these entity types --
for _,surface in pairs(game.surfaces) do
-- These entities --
local all_entities = game.surfaces[surface.index].find_entities_filtered{type = search_types}
-- Now we loop each entity, checking whether or not they are powered --
if(next(all_entities)) then
for _,entity in pairs(all_entities) do
-- Does this entity have power usage and is a part of a network? --
if(entity.is_connected_to_electric_network() == false or entity.power_usage == 0) then
entity.destroy()
end
end
end
end
end
end
Is there a better way to check whether or not an entity is currently powered? The issue comes from the fact that this needs to be "up to date".
As always, I appreciate any and all help/assistance here. Thank you!