concept of electric energy interface

Place to get help with not working mods / modding interface.
Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 80
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

concept of electric energy interface

Post by Hermios »

Hi
I created an entity based on electric-energy-interface. Whatever configuration I set up, the energy of this entity is always 10000.
So, my first question may be : Why cannot I change this value?
More globally, can someone explain precisely (ideally with examples) what the different parameters are for?
I mean, what are
- "energy_per_tick"
- "energy-production"
- "energy-usage"
- "buffer-capacity"
- "input flow limit"
- "output flow limit"
- "drain"

My target : I want to transfer the energy of my entity to a train. But the entity shall not consume energy (or almost nothing) if this is not required. So the energy consumed shall be changed at runtime.
Can you help?
Many thanks.

Subsidiaries question : Is there a way to change the energy_source property of the train at runtime?

Many thanks

Niko
Yoyobuae
Filter Inserter
Filter Inserter
Posts: 511
Joined: Fri Nov 04, 2016 11:04 pm
Contact:

Re: concept of electric energy interface

Post by Yoyobuae »

Hermios wrote:My target : I want to transfer the energy of my entity to a train. But the entity shall not consume energy (or almost nothing) if this is not required. So the energy consumed shall be changed at runtime.
Can you help?
I made something just like this in a mod I made:
https://mods.factorio.com/mods/Yoyobuae ... ransformer

The transformer has two hidden electric-energy-interface entities inside. One drains energy from the electric grid, and the other generates the same amount of energy into a separate grid.

I setup the drain prototype as so:

Code: Select all

    energy_source =
    {
      type = "electric",
      buffer_capacity = "6MJ",
      usage_priority = "secondary-input",
      input_flow_limit = "6MW",
      output_flow_limit = "0W"
    },
The above limits the max power input to 6MW, and allows no power to go back into the grid. This is a bit different from accumulators which do both things. Also I set "usage_priority" to "secondary-input" which allows it to drain power from accumulators (unlike "tertiary" which wouldn't).

Isolated the energy drain calculation from the control.lua file (and added some comments):

Code: Select all

      -- Calculate power transfer value for the next second
      local input_storage = struct.drain.energy

      -- Power is drained from the input buffer.
      -- So the most we can drain from input buffer is the energy in buffer over one second.
      -- If input buffer is full then: 6MJ / 1 second = 6MW
      local max_power_drain = (struct.drain.energy)
      -- Required power drain. Set it to the desired power drain.
      local required_power_drain = 6MW

      -- Limit power transfer to max_power_drain first, then if there's enough 
      -- available input power, set it to required_power_drain
      local power_transfer = 0
      if (max_power < required_power_drain) then
        power_transfer = max_power
      else
        power_transfer = required_power_drain
      end

      -- electric_drain is actually in amount of Joules per tick, instead of Watt units.
      -- Have to divide by number of ticks per second to convert.
      electric_enery_interface_entity.electric_drain = power_transfer / 60.0

      --  Transfer energy that will be drained over the next second into some entity
      entity.energy = entity.energy + power_transfer
Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 80
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: concept of electric energy interface

Post by Hermios »

hi Yoyobuae
Amazingly, it works, although I still didn't understand everything!
Besides, there are some errors in your code (You call it first max_power_drain, then max_power, and I don't know what struc.drain.energy is).
Anyway, many thanks, thanks to you, my mod is ready :)
Yoyobuae
Filter Inserter
Filter Inserter
Posts: 511
Joined: Fri Nov 04, 2016 11:04 pm
Contact:

Re: concept of electric energy interface

Post by Yoyobuae »

Hermios wrote:hi Yoyobuae
Amazingly, it works, although I still didn't understand everything!
Besides, there are some errors in your code (You call it first max_power_drain, then max_power, and I don't know what struc.drain.energy is).
Anyway, many thanks, thanks to you, my mod is ready :)
Opps, sorry. I heavily edited code before posting it, so made some mistakes. struct.drain is the electric-energy-interface which drains power in my mod. Forgot to rename it. (should've used code editor instead of editting while making forum post).

Glad it is working for you, took me quite a few tries to get it working right. Does your mod require variable levels of power drain? Because if it drains only a fixed amount of power, or zero power when idle you could simply set the "input_flow_limit" to that amount of power (in the prototype) and then simply transfer energy directly from the electric-enrergy-interface buffer (by substracting energy from it, while adding it to another entity).

The reason I made my code like that is because the transformer automatically adapts power drain depending on available supply and required demand on the electrical grids, but maybe you don't need that.
Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 80
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: concept of electric energy interface

Post by Hermios »

Well, I have plenty of those energy interface, and they are only used when a train goes on it. So, if I have a constant drain, it will cost many energy for nothing.
Ideally, it just consumes when the train requires it, and something very small (but not 0), when unused. Any idea how to do it?
Thanks

Niko
Post Reply

Return to “Modding help”