api call to get power drawed from electric network

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

api call to get power drawed from electric network

Post by ownlyme »

Hi,
I'm working on an electric interface for my turret energy shields and I want them to loose their energy more quickly, when there is no energy available on the network.
It seems like there is no api to see how much energy the entity actually drains.
When I use is_connected_to_electric_network(), it always returns true as long as there are any power-producers in the network, even if they output nothing, even if they are just empty accumulators.
My request would be to make the function return false if the energy is 0 or very low, or to add a lightweight api call to check how much the entity actually draws from the electric network.

edit: i found a workaround (by caching the stored energy) but still think this should be implemented
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

Rseding91
Factorio Staff
Factorio Staff
Posts: 13236
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: api call to get power drawed from electric network

Post by Rseding91 »

How much energy an entity draws from the electric network depends on what it's doing that tick. If a crafting machine is running it takes some energy based off beacon effects. If it finished crafting that tick it will take 0 next tick unless it resumes crafting.

You can simply read entity.energy > 0 to see if it has energy.
If you want to get ahold of me I'm almost always on Discord.

User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: api call to get power drawed from electric network

Post by ownlyme »

i know, that's why i said i was calculating the energy from tick to tick.
but i assume that since the energy consumption changes every tick, it might be a bit harder to implement that feature.
but you should totally fix that there is no simple way to see if the entity is in a dead electricity network
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: api call to get power drawed from electric network

Post by betrok »

ownlyme wrote:but you should totally fix that there is no simple way to see if the entity is in a dead electricity network
Eh? There is a way:
Rseding91 wrote:You can simply read entity.energy > 0 to see if it has energy.
Though it will not take into account the priority.

Post Reply

Return to “Modding interface requests”