Recipe Ingredients Issues [FIXED]

Place to get help with not working mods / modding interface.
BraveCaperCat
Fast Inserter
Fast Inserter
Posts: 136
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Recipe Ingredients Issues [FIXED]

Post by BraveCaperCat »

When i launch my newly made mod, SE Changes (which i forgot to test) it crashes. The error message is this:

Code: Select all

Failed to load mods: __SEChanges__/data-updates.lua:39: attempt to index field 'ingredients' (a nil value)
stack traceback:
__SEChanges/data-updates.lua:39: in main chunk

Mods to be disabled:
SEChanges (0.1.1) [] Reset mod settings
This is my code (data-updates.lua):

Code: Select all

local function config(name)
    return settings.startup['sec:'.. name].value
end

local SEModPrefix = "se-"

landfill_ingredients = {
    SEModPrefix .. "scrap",
    "iron-ore",
    "copper-ore",
    SEModPrefix .. "iridium-ore",
    SEModPrefix .. "holmium-ore",
    SEModPrefix .. "beryllium-ore"
}

if config("landfill-ores") then
    for _,ingredient in pairs(landfill_ingredients) do
        Recipe = table.deepcopy(data.raw["recipe"]["landfill"])
        Recipe.name = "sec:" .. Recipe.name .. "-crafting"
        Recipe.category = "crafting"
        if config("landfill") then
            Recipe.ingredients[1] = {ingredient, Recipe.ingredients[1][2] / 5}
            Recipe.result_count = Recipe.result_count * 5
        end
        if ingredient == landfill_ingredients[4] then
            table.insert(data.raw["technology"][SEModPrefix .. "processing-iridium"].effects, {type = "unlock_recipe", recipe = Recipe.name})
        elseif ingredient == landfill_ingredients[5] then
            table.insert(data.raw["technology"][SEModPrefix .. "processing-holmium"].effects, {type = "unlock_recipe", recipe = Recipe.name})
        elseif ingredient == landfill_ingredients[6] then
            table.insert(data.raw["technology"][SEModPrefix .. "processing-beryllium"].effects, {type = "unlock_recipe", recipe = Recipe.name})
        else
            Recipe.enabled = true
        end
    end
end

if config("landfill") then
    data.raw["recipe"]["landfill"].ingredients[1] = {"stone", 10}
    data.raw["recipe"]["landfill-sand"].ingredients[1] = {"sand", 40}
    data.raw["recipe"]["landfill"].result_count = data.raw["recipe"]["landfill"].result_count * 5
    data.raw["recipe"]["landfill-sand"].result_count = data.raw["recipe"]["landfill-sand"].result_count * 5

    for _,ingredient in pairs(landfill_ingredients) do
        data.raw["recipe"]["landfill" .. ingredient].result_count = data.raw["recipe"]["landfill" .. ingredient].result_count * 5
        data.raw["recipe"]["landfill" .. ingredient].ingredients[1][2] = data.raw["recipe"]["landfill" .. ingredient].ingredients[1][2] / 5
    end
end
I've looked at the code that makes the landfill and landfill-sand recipes and they look almost exactly the same. The only differences are that landfill sand specifies the icon and allow_decomposition properties. (which the landfill recipe doesn't) This makes no sense, which is why i am asking for help here.
Last edited by BraveCaperCat on Fri Aug 02, 2024 6:53 am, edited 1 time in total.

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 401
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Recipe Ingredients Issues

Post by Stringweasel »

The ingredients table can also be located in normal or expensive, which is probably what's happening. Maybe some other mod is changing it after the code you looked at. This catches a lot of modders, and has been removed for Factorio 2.0. But for now you need to deal with it though. And always good to test your mod before releasing :)
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration

BraveCaperCat
Fast Inserter
Fast Inserter
Posts: 136
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Recipe Ingredients Issues

Post by BraveCaperCat »

Stringweasel wrote:
Thu Aug 01, 2024 2:10 pm
The ingredients table can also be located in normal or expensive, which is probably what's happening. Maybe some other mod is changing it after the code you looked at. This catches a lot of modders, and has been removed for Factorio 2.0. But for now you need to deal with it though. And always good to test your mod before releasing :)
No i looked at the code for SE and the ingredients are defined the same way in both recipes. Why would it fail for the landfill-sand recipe but not the landfill recipe?

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 401
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Recipe Ingredients Issues

Post by Stringweasel »

BraveCaperCat wrote:
Thu Aug 01, 2024 4:23 pm
Stringweasel wrote:
Thu Aug 01, 2024 2:10 pm
The ingredients table can also be located in normal or expensive, which is probably what's happening. Maybe some other mod is changing it after the code you looked at. This catches a lot of modders, and has been removed for Factorio 2.0. But for now you need to deal with it though. And always good to test your mod before releasing :)
No i looked at the code for SE and the ingredients are defined the same way in both recipes. Why would it fail for the landfill-sand recipe but not the landfill recipe?
As I mentioned, some other mod could be changing things after SE declared it, and its still perfectly valid.

It sounds you need to see what you're working. You can use FMTK and set a breakpoint. Or print it with something like:

Code: Select all

log(serpent.block(Recipe))
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration

BraveCaperCat
Fast Inserter
Fast Inserter
Posts: 136
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Recipe Ingredients Issues

Post by BraveCaperCat »

Stringweasel wrote:
Thu Aug 01, 2024 4:42 pm
BraveCaperCat wrote:
Thu Aug 01, 2024 4:23 pm
Stringweasel wrote:
Thu Aug 01, 2024 2:10 pm
The ingredients table can also be located in normal or expensive, which is probably what's happening. Maybe some other mod is changing it after the code you looked at. This catches a lot of modders, and has been removed for Factorio 2.0. But for now you need to deal with it though. And always good to test your mod before releasing :)
No i looked at the code for SE and the ingredients are defined the same way in both recipes. Why would it fail for the landfill-sand recipe but not the landfill recipe?
As I mentioned, some other mod could be changing things after SE declared it, and its still perfectly valid.

It sounds you need to see what you're working. You can use FMTK and set a breakpoint. Or print it with something like:

Code: Select all

log(serpent.block(Recipe))
I have opened the Prototype Explorer. It says that the recipe has ingredients in normal and expensive, but they are exactly the same (not just for ingredients, but for the rest of the contents of normal and expensive too!) so i see no reason to have done that. I also have no idea where that modification happens.

User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 401
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: Recipe Ingredients Issues

Post by Stringweasel »

It doesn't really matter where the modification is done. That is the data that your code has to handle :)
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration

BraveCaperCat
Fast Inserter
Fast Inserter
Posts: 136
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Recipe Ingredients Issues

Post by BraveCaperCat »

You know, it's so funny that i forgot to test the mod before uploading it to the mod portal. And i'm about to do it again with the next version of my mod - which i haven't tested yet.

Post Reply

Return to “Modding help”