Output energy dependent on the global variable

Place to get help with not working mods / modding interface.
Post Reply
User avatar
SLywnow
Inserter
Inserter
Posts: 30
Joined: Sat Apr 25, 2020 7:37 pm
Contact:

Output energy dependent on the global variable

Post by SLywnow »

How to make the output energy dependent on the global variable?
I make some mod, that contain variable in global (because they are tied to the number of objects launched into space). And a certain entity must generate energy in the amount of global.variable / entity.name count in this world * 100Kw. How do I do this?

I only start learning lua (i know С++ and C#) and factorio modding, sorry if this is a stupid question

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Output energy dependent on the global variable

Post by DaveMcW »

data.raw:

Code: Select all

local my_generator = table.deepcopy(data.raw["electric-energy-interface"]["crash-site-generator"])
my_generator.name = "my-generator"
data:extend{my_generator}
control.lua:

Code: Select all

function change_output(surface, force, entity_name)
  local entities = surface.find_entities_filtered{force=force, name=entity_name}
  for _, entity in pairs(entities) do
    entity.power_production = global.variable / #entities * 100000 / 60
  end
end

User avatar
SLywnow
Inserter
Inserter
Posts: 30
Joined: Sat Apr 25, 2020 7:37 pm
Contact:

Re: Output energy dependent on the global variable

Post by SLywnow »

Where do I need to call this function from? I can't find anything suitable in LuaSurface

Post Reply

Return to “Modding help”