API and electricity ?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

API and electricity ?

Post by binbinhfr »

Hi,

what are the possibility to get electric network info from the API ? and to tweak them ?
There is the energy variable on the LuaEntity (mainly for accumulators?), and also the consumption_modifier.
But I did not find any other variables... Is there any ?

Is there a way to
- read the effective consumption of an entity ? for example, to check if an electric consumer is under-electrified (status of the green electric bar on the entity), i.e. consumes less than it could.
- read the global electric production and consumption of one network (the values that are displayed in the panel when you click a pole). And also the global accumulator remaining capacity ?
- change electric consumption of a device on the fly ?

Thanks for your help.
Last edited by binbinhfr on Mon Apr 18, 2016 9:23 am, edited 1 time in total.
My mods on the Factorio Mod Portal :geek:

Quantumtroll
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon Apr 11, 2016 12:10 pm
Contact:

Re: API and electricity ?

Post by Quantumtroll »

binbinhfr wrote:Hi,

what are the possibility to get electric network info from the API ? and to tweak them ?
There is the energy variable on the LuaEntity (mainly for accumulators?), and also the consumption_modifier.
But I did not find any other variables... Is there any ?

Is there a way to
- read the effective consumption of an entity ? for example, to check if an electric consumer is under-electrified (status of the green electric bar on the entity), i.e. consumes less than it could.
- read the global electric production and consumption of one network (the values that are displayed in the panel when you click a pole).
- change electric consumption of a device on the fly ?

Thanks for your help.
I've been working with a similar set of questions. I'm trying to generate a "new pollution" and need to know how effectively my polluter entity is operating, but I can't find any API calls that will let me do that. Reading the electrical consumption of an entity was one proxy that I thought might work, but I think maybe this stuff just isn't in the API (yet). Another possibility was to check actual pollution emission (which surely must be proportional to the building's activity) compared to the prototype's max emission level, but I don't see a way to do even that.

Do you know if there is a way to trigger an event when a given recipe or item is produced? My polluting buildings output sulfur (scrubbed from the air), so if I could keep track of their production it would be enough for me.

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: API and electricity ?

Post by binbinhfr »

Quantumtroll wrote:Do you know if there is a way to trigger an event when a given recipe or item is produced? My polluting buildings output sulfur (scrubbed from the air), so if I could keep track of their production it would be enough for me.
I'm afraid that there is only "on_player_crafted_item", but this event is not triggered by a machine creating an item... If the devs are around here, we would really like some extensions of this nice API :D
My mods on the Factorio Mod Portal :geek:

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: API and electricity ?

Post by binbinhfr »

So no way to get electricity values ?... :(
My mods on the Factorio Mod Portal :geek:

Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: API and electricity ?

Post by Supercheese »

The energy variable should work for any sort of electrically-powered entity. What I'm not sure of, however, is what the maximum value is for e.g. inserters that means "fully powered", as opposed to values less than that, which would mean not fully powered. Of course, testing for zero energy is the trivial case ;) .

You may need to test empirically, by using something like:

Code: Select all

/c game.local_player.print(game.local_player.selected.energy)

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: API and electricity ?

Post by binbinhfr »

good idea, I tested it on several electric entity, but it seems to give logical values only for accumulators. For other devices, the values seem to have no correlation with the object electrical power.

But the fact is that an energy is not a power. And for example, on an assembly machine, you can read the max electric power consumed, and the green bar represents the effective consumed power. This is not an energy but an energy/s. So I doubt that the energy variable contains something useful in that case. :(
My mods on the Factorio Mod Portal :geek:

Quantumtroll
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon Apr 11, 2016 12:10 pm
Contact:

Re: API and electricity ?

Post by Quantumtroll »

No, energy is not useful for anything besides boilers and accumulators. And perhaps batteries and other equipment that have an energy pool, but definitely not energy consumption.

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: API and electricity ?

Post by binbinhfr »

Quantumtroll wrote:No, energy is not useful for anything besides boilers and accumulators. And perhaps batteries and other equipment that have an energy pool, but definitely not energy consumption.
So no clue on how to access these consumption data/variables ?
My mods on the Factorio Mod Portal :geek:

Quantumtroll
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon Apr 11, 2016 12:10 pm
Contact:

Re: API and electricity ?

Post by Quantumtroll »

binbinhfr wrote: So no clue on how to access these consumption data/variables ?
No clue. If I had one, I could continue with my mod!

ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 58
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: API and electricity ?

Post by ss_Baum »

I am actually very late with 5 years and I don't know when they did implement this.

But for all future visitors, now it works with entity.energy.

This returns the stored energy in joule. https://lua-api.factorio.com/latest/Lua ... ity.energy

you can use this, if you just implement the same buffer and the same usage, ore you have to do math.

Post Reply

Return to “Modding help”