Copying recipes script
Posted: Sun Aug 30, 2015 12:00 am
Hello, I have problem with script that supposed to copy recipes that have less than 3 ingredients, then change them a little and add them to recipe list. I am out of ideas how to fix it... I do not have any previous experience with Lua, so probably its noob mistake or so. Here is code:
Thanks in advance for any help!
Code: Select all
function tablelength(T) ---it's to count how many ingredients is in recipe
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
for _, recipe in pairs(data.raw.recipe) do
if recipe.category ~= "pneumatic" and recipe.category ~="smelting" then
if tablelength(recipe.ingredients) < 3 then
local rec = recipe
local energy = recipe.energy_required
rec.name= recipe.name.."-P"
rec.ingredients[3]={type="fluid", name="compressed-air", amount=energy}
rec.category="pneumatic"
data:extend(rec)
end
end
end