recipe.ingredients

Place to get help with not working mods / modding interface.
Post Reply
sore68
Fast Inserter
Fast Inserter
Posts: 123
Joined: Mon May 02, 2016 8:39 am
Contact:

recipe.ingredients

Post by sore68 »

Hi I have a some problem.

I add a new science pack recipes, and add new ingredients array with table.insert.

But this is change original science pack recipes
001.png
001.png (91.17 KiB) Viewed 1571 times

Code: Select all

local item_name = "iron-plate"

local scipack_container = {"science-pack-1", "science-pack-2", "science-pack-3", "military-science-pack", "production-science-pack", "high-tech-science-pack"}

for _, recipe in pairs (data.raw["recipe"]) do
  if string.find(recipe.name, "-pack") then
    for i = 1, #scipack_container do
      if recipe.name == scipack_container[i] then
        data:extend({
          sp_recipe{
            name = "AA_"..recipe.name,
            energy_required = recipe.energy_required * 2,
            order = i.."-alien-science-"..scipack_container[i],
            icon = "__Additional-Alien__/graphics/icon/"..recipe.name..".png",
            ingredients = recipe.ingredients,
            results = {{type = "item", name = recipe.name, amount = 3}}
          }
        })
        table.insert(data.raw.recipe["AA_"..recipe.name].ingredients, 1, {item_name, i*5})
        -- table.insert(data.raw.recipe[scipack_container[i]].ingredients, 1, {item_name, i*5})
        -- table.remove(data.raw.recipe[scipack_container[i]].ingredients, 1)
      end
    end
  end
end

Could you tell me why the problem occurred??

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: recipe.ingredients

Post by Choumiko »

If i understand it right you want to add new recipes for the existing science, that require an additinal ingredient but produce more of the science pack?

In that case:

Code: Select all

require 'util'
local item_name = "iron-plate"
local scipack_container = {"science-pack-1", "science-pack-2", "science-pack-3", "military-science-pack", "production-science-pack", "high-tech-science-pack"}

for i, name in pairs(scipack_container) do
    local recipe = data.raw.recipe[name]
    data:extend({
        {
            type = "recipe",
            name = "AA_"..recipe.name,
            energy_required = recipe.energy_required * 2,
            order = i.."-alien-science-"..scipack_container[i],
            --icon = "__Additional-Alien__/graphics/icon/"..recipe.name..".png",
            ingredients = table.deepcopy(recipe.ingredients),
            results = {{type = "item", name = recipe.name, amount = 3}}
        }
    })
    table.insert(data.raw.recipe["AA_"..recipe.name].ingredients, 1, {item_name, i*5})
end
should work (untested). The new recipes will be available from the start though, you'll have to modifiy the technologies that unlock them to also unlock your recipes.
The problem with your code was that it modified a reference to the original tables, table.deepcopy solves that.

sore68
Fast Inserter
Fast Inserter
Posts: 123
Joined: Mon May 02, 2016 8:39 am
Contact:

Re: recipe.ingredients

Post by sore68 »

Choumiko wrote: ...

Wow!
Now it works just as I intended!
thank you so love Choumiko :D
001.png
001.png (312.89 KiB) Viewed 1541 times

Post Reply

Return to “Modding help”