Page 1 of 1
Can you realize the dynamic conversion of formula
Posted: Sun Apr 03, 2022 12:34 am
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?
Re: Can you realize the dynamic conversion of formula
Posted: Sun Apr 03, 2022 1:31 am
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}
Re: Can you realize the dynamic conversion of formula
Posted: Sun Apr 03, 2022 2:41 am
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?
Re: Can you realize the dynamic conversion of formula
Posted: Mon Apr 04, 2022 7:15 am
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.
Re: Can you realize the dynamic conversion of formula
Posted: Tue Apr 05, 2022 12:34 am
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