Page 1 of 1

Change Recipe using Setting

Posted: Fri Jun 21, 2024 9:09 pm
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.

Re: Change Recipe using Setting

Posted: Thu Aug 01, 2024 1:08 am
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)