Can you realize the dynamic conversion of formula

Place to get help with not working mods / modding interface.
Post Reply
sdgmlj
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Can you realize the dynamic conversion of formula

Post by sdgmlj »

I want to realize the mutual conversion between minerals without adding intermediate items. My idea is as follows:

After I manually select the output items, the input raw materials are variable, and I may not be able to express them clearly. Use the following script to give an example:
data:extend(
{
{
type = "recipe",
name = "transformation-iron-ore",
ingredients =
{
{"copper-ore", 5},
or {"coal", 5},
or {"stonel", 5},
},
result = "iron-ore"
},
{
type = "recipe",
name = "transformation-copper-ore",
ingredients =
{
{"iron-ore", 5},
or {"coal", 5},
or {"stonel", 5},
},
result = "copper-ore"
},
}
)
I know using "or" is definitely not good. I just want to express my meaning. Can my idea be realized?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Can you realize the dynamic conversion of formula

Post by DaveMcW »

No, not with a recipe. But you can do it with a unique furnace for each output.

Code: Select all

data:extend{
  {
    type = "recipe-category",
    name = "transformation-iron-ore",
  },
  {
    type = "recipe-category",
    name = "transformation-copper-ore",
  },
  {
    type = "recipe",
    name = "transformation-iron-ore-from-copper-ore",
    category = "transformation-iron-ore",
    ingredients = {{"copper-ore", 5}},
    result = "iron-ore",
  },
  {
    type = "recipe",
    name = "transformation-iron-ore-from-coal",
    category = "transformation-iron-ore",
    ingredients = {{"coal", 5}},
    result = "iron-ore",
  },
  {
    type = "recipe",
    name = "transformation-iron-ore-from-stone",
    category = "transformation-iron-ore",
    ingredients = {{"stone", 5}},
    result = "iron-ore",
  },
  {
    type = "recipe",
    name = "transformation-copper-ore-from-iron-ore",
    category = "transformation-copper-ore",
    ingredients = {{"iron-ore", 5}},
    result = "copper-ore",
  },
  {
    type = "recipe",
    name = "transformation-copper-ore-from-coal",
    category = "transformation-copper-ore",
    ingredients = {{"coal", 5}},
    result = "copper-ore",
  },
  {
    type = "recipe",
    name = "transformation-copper-ore-from-stone",
    category = "transformation-copper-ore",
    ingredients = {{"stone", 5}},
    result = "copper-ore",
  },
}

local furnace = table.deepcopy(data.raw["furnace"]["electric-furnace"])
furnace.name = "transformation-iron-ore"
furnace.minable.result = "transformation-iron-ore"
furnace.crafting_categories = {"transformation-iron-ore"}
data:extend{furnace}

local item = table.deepcopy(data.raw["item"]["electric-furnace"])
item.name = "transformation-iron-ore"
item.place_result = "transformation-iron-ore"
data:extend{item}

furnace = table.deepcopy(data.raw["furnace"]["electric-furnace"])
furnace.name = "transformation-copper-ore"
furnace.minable.result = "transformation-copper-ore"
furnace.crafting_categories = {"transformation-copper-ore"}
data:extend{furnace}

item = table.deepcopy(data.raw["item"]["electric-furnace"])
item.name = "transformation-copper-ore"
item.place_result = "transformation-copper-ore"
data:extend{item}

sdgmlj
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Re: Can you realize the dynamic conversion of formula

Post by sdgmlj »

DaveMcW wrote:
Sun Apr 03, 2022 1:31 am
No, not with a recipe. But you can do it with a unique furnace for each output.

Code: Select all

data:extend{
  {
    type = "recipe-category",
    name = "transformation-iron-ore",
  },
  {
    type = "recipe-category",
    name = "transformation-copper-ore",
  },
  {
    type = "recipe",
    name = "transformation-iron-ore-from-copper-ore",
    category = "transformation-iron-ore",
    ingredients = {{"copper-ore", 5}},
    result = "iron-ore",
  },
  {
    type = "recipe",
    name = "transformation-iron-ore-from-coal",
    category = "transformation-iron-ore",
    ingredients = {{"coal", 5}},
    result = "iron-ore",
  },
  {
    type = "recipe",
    name = "transformation-iron-ore-from-stone",
    category = "transformation-iron-ore",
    ingredients = {{"stone", 5}},
    result = "iron-ore",
  },
  {
    type = "recipe",
    name = "transformation-copper-ore-from-iron-ore",
    category = "transformation-copper-ore",
    ingredients = {{"iron-ore", 5}},
    result = "copper-ore",
  },
  {
    type = "recipe",
    name = "transformation-copper-ore-from-coal",
    category = "transformation-copper-ore",
    ingredients = {{"coal", 5}},
    result = "copper-ore",
  },
  {
    type = "recipe",
    name = "transformation-copper-ore-from-stone",
    category = "transformation-copper-ore",
    ingredients = {{"stone", 5}},
    result = "copper-ore",
  },
}

local furnace = table.deepcopy(data.raw["furnace"]["electric-furnace"])
furnace.name = "transformation-iron-ore"
furnace.minable.result = "transformation-iron-ore"
furnace.crafting_categories = {"transformation-iron-ore"}
data:extend{furnace}

local item = table.deepcopy(data.raw["item"]["electric-furnace"])
item.name = "transformation-iron-ore"
item.place_result = "transformation-iron-ore"
data:extend{item}

furnace = table.deepcopy(data.raw["furnace"]["electric-furnace"])
furnace.name = "transformation-copper-ore"
furnace.minable.result = "transformation-copper-ore"
furnace.crafting_categories = {"transformation-copper-ore"}
data:extend{furnace}

item = table.deepcopy(data.raw["item"]["electric-furnace"])
item.name = "transformation-copper-ore"
item.place_result = "transformation-copper-ore"
data:extend{item}
Thank you, my friend. You explained it very carefully. I see what you mean.

But I also want to ask if it is too troublesome to add a device for each material. Is there no way to synthesize them into one?

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Can you realize the dynamic conversion of formula

Post by darkfrei »

Table

Code: Select all

tabl ={
  {
    type = "recipe",
    name = "transformation-copper-ore-from-coal",
    category = "transformation-copper-ore",
    ingredients = {{"coal", 5}},
    result = "copper-ore",
  },
  {
    type = "recipe",
    name = "transformation-copper-ore-from-stone",
    category = "transformation-copper-ore",
    ingredients = {{"stone", 5}},
    result = "copper-ore",
  },
}
Is same as

Code: Select all

local list = {"coal", "stone"}
local tabl = {}
for i, name in ipairs (list) do
  local recipe ={
    type = "recipe",
    name = "transformation-copper-ore-from-" .. name,
    category = "transformation-copper-ore",
    ingredients = {{name, 5}},
    result = "copper-ore",
  }
  table.insert (tabl, recipe)
end
So you can do it procedurally.

sdgmlj
Fast Inserter
Fast Inserter
Posts: 127
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

Re: Can you realize the dynamic conversion of formula

Post by sdgmlj »

darkfrei wrote:
Mon Apr 04, 2022 7:15 am
Table

Code: Select all

tabl ={
  {
    type = "recipe",
    name = "transformation-copper-ore-from-coal",
    category = "transformation-copper-ore",
    ingredients = {{"coal", 5}},
    result = "copper-ore",
  },
  {
    type = "recipe",
    name = "transformation-copper-ore-from-stone",
    category = "transformation-copper-ore",
    ingredients = {{"stone", 5}},
    result = "copper-ore",
  },
}
Is same as

Code: Select all

local list = {"coal", "stone"}
local tabl = {}
for i, name in ipairs (list) do
  local recipe ={
    type = "recipe",
    name = "transformation-copper-ore-from-" .. name,
    category = "transformation-copper-ore",
    ingredients = {{name, 5}},
    result = "copper-ore",
  }
  table.insert (tabl, recipe)
end
So you can do it procedurally.
Thank you. I see

Post Reply

Return to “Modding help”