Page 1 of 1

Output energy dependent on the global variable

Posted: Wed Aug 12, 2020 1:24 am
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

Re: Output energy dependent on the global variable

Posted: Wed Aug 12, 2020 2:31 am
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

Re: Output energy dependent on the global variable

Posted: Wed Aug 12, 2020 3:25 pm
by SLywnow
Where do I need to call this function from? I can't find anything suitable in LuaSurface