[0.17.79] LuaEntity.is_connected_to_electric_network() is wrong

Bugs that are actually features.
Post Reply
PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

[0.17.79] LuaEntity.is_connected_to_electric_network() is wrong

Post by PyroFire »

It would appear that LuaEntity.is_connected_to_electric_network() doesn't actually tell you if an entity is connected to an electric network or not.
Instead, it tells you if the entity is connected to an electric network that has an energy source.

I.e.

Calling this on the assembler returns false, even though it is clearly connected to an electric network.

Image

If i now then add an electrical source like an accumulator or a steam engine, now it will return true regardless if there is any electricity in it or not.

Image

This seems like a bug because even though it is connected to an electric network, the flashing alert icon says it's not connected to anything, even though it is.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2244
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [0.17.79] LuaEntity.is_connected_to_electric_network() is wrong

Post by boskid »

I will count this as Not a bug

is_connected_to_electric_network is exactly same check as for disconnected icon. It is implemented to look for energy producers and is looks intentional.

If you want to detect if entity is in range of any electric pole, you may use LuaEntity.electric_network_id read: for entities outside of any power poles it will be nil. For entities in range of at least one power pole you will get non-nil value. In case of multiple networks in range you will get ID of only one of them, but still non-nil.

Post Reply

Return to “Not a bug”