Change Recipe using Setting

Place to get help with not working mods / modding interface.
Lead_Hail
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Jan 28, 2022 2:55 am
Contact:

Change Recipe using Setting

Post by Lead_Hail »

I noticed a mod I was using had an unbalanced recipe for Large Solar Farm, that supplied twice as much power than it should.
I tried to add a setting to the mod that would double the cost of the recipe. I belive I added the setting correctly but I can't figure out how to make the setting control the recipe.
Attachments
vanilla.lua
recipes file.
(845 Bytes) Downloaded 30 times
settings.lua
(166 Bytes) Downloaded 22 times

penfold1992
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Aug 01, 2024 12:49 am
Contact:

Re: Change Recipe using Setting

Post by penfold1992 »

I have the same question, albeit slightly differently...
I want to know if its possible to change the recipes in the `global` or per-map settings.

My initial thought is "no" because I dont think you can modify prototypes after the data phase...

To answer your question:
In your vanilla.lua file, you can load the settings and use them in the recipe
HUGE CAVEAT: I am new to the scene, I am new to Lua as well (I have experience in other languages) so please take my advise with a grain of salt...

Code: Select all

hard_recipes = settings.startup["hard-rceipes"].value  -- Note, this spelling mistake matches that of the settings.lua file you provided

recipes = {
  {
    type = "recipe",
    category = "basic-crafting",
    name = "small-solar-farm",
    normal = {
      enabled = false,
      ingredients = {
        {"solar-panel", 100},
      },
      energy_required = 5,
      result = "small-solar-farm",
    },
  },
  {
    type = "recipe",
    category = "basic-crafting",
    name = "medium-solar-farm",
    normal = {
      enabled = false,
      ingredients = {
        {"solar-panel", 200},
      },
      energy_required = 5,
      result = "medium-solar-farm",
    },
  },
  {
    type = "recipe",
    category = "basic-crafting",
    name = "large-solar-farm",
    normal = {
      enabled = false,
      ingredients = {
        {"solar-panel", 400},
      },
      energy_required = 5,
      result = "large-solar-farm",
    },
  }
}

if hard_recipes then
  for _, recipe in ipairs(recipes) do
    for _, ingredient in recipe.ingredients do
      ingredient.amount = ingredient.amount*2
    end  
  end
end

data:extend(recipes)


Post Reply

Return to “Modding help”