[2.0.76] Enumerating all know electrical networks on a surface

Place to get help with not working mods / modding interface.
User avatar
hgschmie
Fast Inserter
Fast Inserter
Posts: 169
Joined: Tue Feb 06, 2024 5:18 am
Contact:

[2.0.76] Enumerating all know electrical networks on a surface

Post by hgschmie »

Right now, I am using code similar to this:

Code: Select all

local surface_index = 1
local known_networks = {}
for _, e in pairs (game.surfaces[surface_index].find_entities_filtered { type = 'electric-pole' }) do
    known_networks[e.electric_network_id] = true
end

for id in pairs(known_networks) do
    print(id)
end
to enumerate all known electric networks on a surface. This seems cumbersome. Is there a better way to do that? I was hoping for a LuaSurface#get_all_electrical_networks() or so but there seems to be nothing.
Post Reply

Return to “Modding help”