getting list of recipes with normal/expensive ingrediants
Posted: Mon Jun 25, 2018 8:07 am
a have a script that loops thru all the recipes in the game and adds them to a list that is then looped thru to check for and replace a specific ingredient from a list with another. it works for all recipes that are just recipe.ingredients. if a recipe contains normal and expensive ingredients it does not work. from googling it seems that i needed to add "normal" to specify that but doesnt seem to have done anything
first part gets the list of recipes and second section loops thru and replaces the items
this one should loop thru the normal.ingredients list
i cant tell if its falling to populate the n_e_recipes list or where else the issue is.
first part gets the list of recipes and second section loops thru and replaces the items
Code: Select all
local test_list = {}
local n_e_recipes = {}
for i, recipe in pairs(data.raw.recipe) do
if recipe.ingredients then
table.insert(test_list,recipe.name)
elseif recipe.normal.ingredients then
table.insert(n_e_recipes,recipe.name)
end
end
for i, recipe_name in ipairs(test_list) do
local ingredients = table.deepcopy(data.raw.recipe[recipe_name].ingredients)
for k, ingredient in ipairs(ingredients) do
for j,l in pairs(items_dict) do
if ingredient.name == j then
local recipeingredamount = (table.deepcopy(data.raw.recipe[recipe_name].ingredients[k].amount))
data.raw.recipe[recipe_name].ingredients[k] = {l, recipeingredamount}
end
end
end
end
Code: Select all
for i, recipe_name in ipairs(n_e_recipes) do
local ingredients = table.deepcopy(data.raw.recipe[recipe_name].normal.ingredients)
for k, ingredient in ipairs(ingredients) do
for j, item_name in ipairs(items_list) do
if ingredient.name == item_name then
local recipeingredamount = (table.deepcopy(data.raw.recipe[recipe_name].normal.ingredients[k].amount))
data.raw.recipe[recipe_name].normal.ingredients[k] = {replacement_item, recipeingredamount}
end
end
end
end