Unable to modify the Solar-Panel property during runtime

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
jinx13
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Apr 05, 2016 1:06 am
Contact:

Unable to modify the Solar-Panel property during runtime

Post by jinx13 »

Is there a way to modify the properties of an entity during runtime.

Example:

I have created a new research to increase the output of the solar panel by 5% per level.

I have the research working.
But I am not able to increase the production value of the solar panel.

I have this code in control.lua

Code: Select all

script.on_event(defines.events.on_research_finished, function(event)
  local research = event.research
  -- Check if the finished research is related to solar panel efficiency
  if research.name == "solar-panel-efficiency" then
    -- Calculate the new power output based on the level of efficiency researched
    local level = research.level
    local new_output = 0.06 * (1 + (level * 0.1)) -- Base output is 60kW, which is 0.06MW, each level adds 10%
    -- Update the production of all solar panels
    for _, surface in pairs(game.surfaces) do
      for _, panel in pairs(surface.find_entities_filtered{type="solar-panel"}) do
        panel.production = new_output .. "MW" --Getting an error on this line.
      end
    end
  end
end)


I have this code in data-updates.lua which works. But I wanted this to be a researched effect instead.

Code: Select all

data.raw["solar-panel"]["solar-panel"].production= "0.6MW" --For testing
If you are interested, here is the technology research code.

Code: Select all

data:extend({
  {
    type = "technology",
    name = "solar-panel-efficiency",
    icon_size = 256,
    icons = util.technology_icon_constant_stack_size("__base__/graphics/technology/solar-energy.png"),
    effects = {},
    prerequisites = {"solar-energy"},
    unit =
    {
      count_formula = "((L*100)^2)",
      ingredients =
      {
	{"military-science-pack", 1},
        {"automation-science-pack", 1},
        {"logistic-science-pack", 1},
        {"chemical-science-pack", 1},
        {"production-science-pack", 1},
        {"utility-science-pack", 1},
        {"space-science-pack", 1}
      },
      time = 30
    },
    upgrade = true,
    max_level = "infinite",
    order = "a-h-a"
  }
})

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Unable to modify the Solar-Panel property during runtime

Post by FuryoftheStars »

jinx13 wrote:
Wed May 01, 2024 11:43 am
Is there a way to modify the properties of an entity during runtime.
No. The power produced by an entity is not modifiable at runtime. Best you could do is define separate entities for each tech research and then swap them out as you go.

Take a look through the API docs some. Properties of entities and the like that can be changed at runtime are marked as RW (read/write).

There's also a defined list of things that can be improved directly via research in the TechnologyPrototype effects.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics

jinx13
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Apr 05, 2016 1:06 am
Contact:

Re: Unable to modify the Solar-Panel property during runtime

Post by jinx13 »

Thank you.
I always wondered why nobody ever made such a mod. :? :)

Post Reply

Return to “Modding discussion”