How to get recipe icons of all recipes [SOLVED]
Posted: Wed Aug 03, 2022 7:18 pm
I'm trying to create a sprite button table filled with every recipe in the game (including mods). The best way to do that seems to be looping through the recipe prototypes in game.players[playerIndex].force.recipes. However, I am uncertain how to get the recipe icons for each recipe. Just using "item/recipe.name" doesn't work for, for example, fluid recipes, creating dozens of ifs isn't really feasible, and I don't even know if "item/recipe.name" would work for modded stuff.
Using Lua API global Variable Viewer, the recipes in force don't contain "icon" even though the recipe Prototype definition does? Then how is it possible to retrieve the icon of a recipe, and making it mod compatible. Looping through force.recipes really seems to be the way, since that contains all recipes in the whole game, modded included.
Code snippet of my loop (currently set up to only print the icon of the recipe):
Returns this error:
Using Lua API global Variable Viewer, the recipes in force don't contain "icon" even though the recipe Prototype definition does? Then how is it possible to retrieve the icon of a recipe, and making it mod compatible. Looping through force.recipes really seems to be the way, since that contains all recipes in the whole game, modded included.
Code snippet of my loop (currently set up to only print the icon of the recipe):
Code: Select all
function build_sprite_buttons(player)
local button_table = player.gui.screen["cc_configWindow"].cc_contentFrame.button_frame.button_table
button_table.clear()
for _, recipe in pairs(player.force.recipes) do
game.print(tostring(recipe.icon))
end
end
Error while running event crafting_cleanup::on_player_created (ID 26)
LuaRecipe doesn't contain key icon.
stack traceback:
[C]: in function '__index'
__crafting_cleanup__/control.lua:134: in function 'build_sprite_buttons'
__crafting_cleanup__/control.lua:246: in function 'createConfigWindow'
__crafting_cleanup__/control.lua:259: in function <__crafting_cleanup__/control.lua:250>