What constitutes an electric network?

Place to get help with not working mods / modding interface.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1759
Joined: Sun Oct 14, 2018 8:13 am
Contact:

What constitutes an electric network?

Post by Pi-C »

I want to burn small-electric-poles that carry power. Poles don't store energy, so they don't have the entity.energy property. But they can be connected, so we should be able to use entity.is_connected_to_electric_network(). But if I let this code

Code: Select all

if ent and ent.type == "electric-pole" and ent.name == "small-electric-pole" then
  log(string.format("%s (%s) is connected: %s\tNetwork ID: %s\tNeighbours: %s", ent.name, ent.unit_number, ent.is_connected_to_electric_network(), ent.electric_network_id, ent.neighbours["copper"]))
end
I get this output:

Code: Select all

small-electric-pole (34) is connected: false	Network ID: 1	Neighbours: small-electric-pole
for this setup:
electric-network.png
electric-network.png (2.58 MiB) Viewed 661 times
The two poles are in reach of the Active power source from Creative Mod, they are connected to each other, and they even have an active consumer (the lamp). In my opinion, this would qualify as an electric network -- but the test for is_connected_to_electric_network() fails. So, when is an electric network an electric network? :-)

Bonus question: Is there a way to read how much power goes over a wire?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4059
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: What constitutes an electric network?

Post by boskid »

is_connected_to_electric_network checks if:
a/ given entity has energy source
b/ is electric energy source
c/ has connection to any network or additional network that contains energy producers.
Power pole does not have energy source so it fails.
Pi-C wrote: Wed Nov 11, 2020 3:09 pmBonus question: Is there a way to read how much power goes over a wire?
No, and it will not happen. Power poles are only used to determine which entities are considered connected and then energy flow is like teleportation: check available energy and required consumption, compute some values and remove energy from producers and add energy to consumers.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1759
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: What constitutes an electric network?

Post by Pi-C »

boskid wrote: Wed Nov 11, 2020 3:18 pm is_connected_to_electric_network checks if:
a/ given entity has energy source
b/ is electric energy source
c/ has connection to any network or additional network that contains energy producers.
Power pole does not have energy source so it fails.
Thanks for the explanation! So, instead of using the amount of power carried via a wire, I'll introduce a random factor to decide if a pole should burn. Not quite as nice, but probably the easiest workaround. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Post Reply

Return to “Modding help”