Page 1 of 1
[Solved][2.0.43] How can I set the icon for a recipe?
Posted: Sun Apr 27, 2025 4:29 pm
by yaim904
Context
I am creating a new object with its own icon. The new object is used in two recipes.
What I am trying to do is that each recipe has a different icon.
The following code is functional and the image shows the problem.
Code: Select all
---------------------------------------------------------------------------------------------------
---> data.lua <---
---------------------------------------------------------------------------------------------------
local function DeepCopy(value)
if type(value) ~= "table" then return value end
local Output = {}
for Key, Value in pairs(value) do
Output[Key] = DeepCopy(Value)
end
return Output
end
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local StackSize = 500
local Ingredients = 1000
local ArrowU = { icon = data.raw["virtual-signal"]["up-arrow"].icon, scale = 0.30 }
local ArrowD = { icon = data.raw["virtual-signal"]["down-arrow"].icon, scale = 0.30 }
local Item = {}
local item_name = "solid-fuel"
local Prefix = "zzzYAIM904-"
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local item = data.raw.item[item_name]
local Properties = {}
table.insert(Properties, "localised_name")
table.insert(Properties, "inventory_move_sound")
table.insert(Properties, "pick_sound")
table.insert(Properties, "drop_sound")
table.insert(Properties, "subgroup")
table.insert(Properties, "order")
table.insert(Properties, "icons")
for _, key in pairs(Properties) do
Item[key] = DeepCopy(item[key])
end
Item.name = Prefix .. item.name
Item.type = "item"
Item.stack_size = StackSize
Item.localised_description = { "" }
table.insert(Item.localised_description, Ingredients .. " ")
table.insert(Item.localised_description, "[item=" .. item.name .. "] ")
table.insert(Item.icons, ArrowU)
data:extend({ Item })
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local RecipeD = {}
RecipeD.type = "recipe"
RecipeD.name = Item.name
RecipeD.localised_name = DeepCopy(item.localised_name)
RecipeD.icons = DeepCopy(item.icons)
RecipeD.allow_decomposition = false
RecipeD.allow_as_intermediate = false
RecipeD.hide_from_player_crafting = true
RecipeD.enabled = true
RecipeD.results = { { type = "item", name = Item.name, amount = 1 } }
RecipeD.ingredients = { { type = "item", name = item.name, amount = Ingredients } }
RecipeD.subgroup = item.subgroup
RecipeD.order = item.order
table.insert(RecipeD.icons, ArrowD)
data:extend({ RecipeD })
local RecipeU = {}
RecipeU.type = "recipe"
RecipeU.name = Prefix .. "-u-" .. item.name
RecipeU.localised_name = DeepCopy(item.localised_name)
RecipeU.icons = DeepCopy(item.icons)
RecipeU.allow_decomposition = false
RecipeU.enabled = true
RecipeU.ingredients = { { type = "item", name = Item.name, amount = 1 } }
RecipeU.results = { { type = "item", name = item.name, amount = Ingredients } }
RecipeU.subgroup = item.subgroup
RecipeU.order = item.order
table.insert(RecipeU.icons, ArrowU)
data:extend({ RecipeU })

- (100).png (657.72 KiB) Viewed 230 times
The recipe has a different icon than the object icon in the code, but the recipe icon is being ignored and the object icon is being used. The object icon is also being used by the second recipe. This results in two recipes with the same icon even though the code says otherwise.
How can I change this?
Re: [2.0.43] How can I set the icon for a recipe?
Posted: Mon Apr 28, 2025 10:50 am
by yaim904
What I mean is, what is the point of defining the icons of the recipes if in the end they will be ignored and another one will be used.
Re: [2.0.43] How can I set the icon for a recipe?
Posted: Tue Apr 29, 2025 9:11 am
by DaveMcW
Try giving the recipe and item a different localised_name.
Re: [2.0.43] How can I set the icon for a recipe?
Posted: Wed Apr 30, 2025 1:32 am
by yaim904
DaveMcW wrote: Tue Apr 29, 2025 9:11 am
I changed the localised_name in the following code but it is the same result.
Code: Select all
---------------------------------------------------------------------------------------------------
---> data.lua <---
---------------------------------------------------------------------------------------------------
local function DeepCopy(value)
if type(value) ~= "table" then return value end
local Output = {}
for Key, Value in pairs(value) do
Output[Key] = DeepCopy(Value)
end
return Output
end
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local StackSize = 500
local Ingredients = 1000
local ArrowU = { icon = data.raw["virtual-signal"]["up-arrow"].icon, scale = 0.30 }
local ArrowD = { icon = data.raw["virtual-signal"]["down-arrow"].icon, scale = 0.30 }
local NewItem = {}
local item_name = "solid-fuel"
local Prefix = "zzzYAIM904-"
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local OriginalItem = data.raw.item[item_name]
local Properties = {}
table.insert(Properties, "localised_name")
table.insert(Properties, "inventory_move_sound")
table.insert(Properties, "pick_sound")
table.insert(Properties, "drop_sound")
table.insert(Properties, "subgroup")
table.insert(Properties, "order")
table.insert(Properties, "icons")
for _, key in pairs(Properties) do
NewItem[key] = DeepCopy(OriginalItem[key])
end
NewItem.name = Prefix .. OriginalItem.name
NewItem.type = "item"
NewItem.stack_size = StackSize
NewItem.localised_description = { "" }
table.insert(NewItem.localised_description, Ingredients .. " ")
table.insert(NewItem.localised_description, "[item=" .. OriginalItem.name .. "] ")
table.insert(NewItem.icons, ArrowU)
data:extend({ NewItem })
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local RecipeD = {}
RecipeD.type = "recipe"
RecipeD.name = NewItem.name
RecipeD.localised_name = DeepCopy(OriginalItem.localised_name)
RecipeD.icons = DeepCopy(OriginalItem.icons)
RecipeD.allow_decomposition = false
RecipeD.allow_as_intermediate = false
RecipeD.hide_from_player_crafting = true
RecipeD.enabled = true
RecipeD.results = { { type = "item", name = NewItem.name, amount = 1 } }
RecipeD.ingredients = { { type = "item", name = OriginalItem.name, amount = Ingredients } }
RecipeD.subgroup = OriginalItem.subgroup
RecipeD.order = OriginalItem.order
table.insert(RecipeD.icons, ArrowD)
data:extend({ RecipeD })
local RecipeU = {}
RecipeU.type = "recipe"
RecipeU.name = Prefix .. "-u-" .. OriginalItem.name
RecipeU.localised_name = DeepCopy(OriginalItem.localised_name)
RecipeU.icons = DeepCopy(OriginalItem.icons)
RecipeU.allow_decomposition = false
RecipeU.enabled = true
RecipeU.ingredients = { { type = "item", name = NewItem.name, amount = 1 } }
RecipeU.results = { { type = "item", name = OriginalItem.name, amount = Ingredients } }
RecipeU.subgroup = OriginalItem.subgroup
RecipeU.order = OriginalItem.order
table.insert(RecipeU.icons, ArrowU)
data:extend({ RecipeU })
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
NewItem.localised_name = "xXx"
RecipeD.localised_name = "vVv"
RecipeU.localised_name = "mMm"

- Captura de pantalla (226).png (358.4 KiB) Viewed 116 times

- Captura de pantalla (225).png (345.41 KiB) Viewed 116 times
Another suggestion please.
Re: [2.0.43] How can I set the icon for a recipe?
Posted: Wed Apr 30, 2025 3:54 am
by DaveMcW
How about a different "name"?
Re: [2.0.43] How can I set the icon for a recipe?
Posted: Wed Apr 30, 2025 1:43 pm
by yaim904
DaveMcW wrote: Wed Apr 30, 2025 3:54 am
Changing the names separates the recipes from the object.
It's not what I expected but it might work for me.
Thank you.
I still find it strange that the recipe ignores its own icons in favour of the result icons.
Code: Select all
---------------------------------------------------------------------------------------------------
---> data.lua <---
---------------------------------------------------------------------------------------------------
local function DeepCopy(value)
if type(value) ~= "table" then return value end
local Output = {}
for Key, Value in pairs(value) do
Output[Key] = DeepCopy(Value)
end
return Output
end
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local StackSize = 500
local Ingredients = 1000
local ArrowU = { icon = data.raw["virtual-signal"]["up-arrow"].icon, scale = 0.30 }
local ArrowD = { icon = data.raw["virtual-signal"]["down-arrow"].icon, scale = 0.30 }
local Stack_size = { icon = data.raw["virtual-signal"]["signal-stack-size"].icon, scale = 0.30 }
local NewItem = {}
local item_name = "solid-fuel"
local Prefix = "zzzYAIM904-"
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local OriginalItem = data.raw.item[item_name]
local Properties = {}
table.insert(Properties, "localised_name")
table.insert(Properties, "inventory_move_sound")
table.insert(Properties, "pick_sound")
table.insert(Properties, "drop_sound")
table.insert(Properties, "subgroup")
table.insert(Properties, "order")
table.insert(Properties, "icons")
for _, key in pairs(Properties) do
NewItem[key] = DeepCopy(OriginalItem[key])
end
NewItem.name = Prefix .. OriginalItem.name
NewItem.type = "item"
NewItem.stack_size = StackSize
NewItem.localised_description = { "" }
table.insert(NewItem.localised_description, Ingredients .. " ")
table.insert(NewItem.localised_description, "[item=" .. OriginalItem.name .. "] ")
table.insert(NewItem.icons, Stack_size)
data:extend({ NewItem })
--- --- --- --- --- --- --- --- --- --- --- --- --- ---
local RecipeD = {}
RecipeD.type = "recipe"
RecipeD.name = Prefix .. "-d-" .. OriginalItem.name
RecipeD.localised_name = DeepCopy(OriginalItem.localised_name)
RecipeD.icons = DeepCopy(OriginalItem.icons)
RecipeD.allow_decomposition = false
RecipeD.allow_as_intermediate = false
RecipeD.hide_from_player_crafting = true
RecipeD.enabled = true
RecipeD.results = { { type = "item", name = NewItem.name, amount = 1 } }
RecipeD.ingredients = { { type = "item", name = OriginalItem.name, amount = Ingredients } }
RecipeD.subgroup = OriginalItem.subgroup
RecipeD.order = OriginalItem.order
table.insert(RecipeD.icons, ArrowD)
data:extend({ RecipeD })
local RecipeU = {}
RecipeU.type = "recipe"
RecipeU.name = NewItem.name
RecipeU.localised_name = DeepCopy(OriginalItem.localised_name)
RecipeU.icons = DeepCopy(OriginalItem.icons)
RecipeU.allow_decomposition = false
RecipeU.enabled = true
RecipeU.ingredients = { { type = "item", name = NewItem.name, amount = 1 } }
RecipeU.results = { { type = "item", name = OriginalItem.name, amount = Ingredients } }
RecipeU.subgroup = OriginalItem.subgroup
RecipeU.order = OriginalItem.order
table.insert(RecipeU.icons, ArrowU)
data:extend({ RecipeU })

- Captura de pantalla (230).png (332 KiB) Viewed 69 times

- Captura de pantalla (231).png (348.71 KiB) Viewed 69 times

- Captura de pantalla (232).png (348.45 KiB) Viewed 69 times