Recursive Prototype alteration: Resolved

Place to get help with not working mods / modding interface.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Recursive Prototype alteration: Resolved

Post by Ranakastrasz »

I am unsure why it is that if I enable the process function in my "Data final Fixes" function, it claims that recipe wood has no name node.
I don't even alter name at any point.

I am pretty sure there is no infinite loop here, but without debug messages, I can't be certain.

Code: Select all

function process(recipe)
    if not recipe.processed then
        local energy = 0.5
        if recipe.ingredients then
            for i, ingredient in pairs(recipe.ingredients) do
                --process(ingredient) -- This here
                energy = energy + 0.3
                if ingredient[2] then
                    energy = energy + 0.2*ingredient[2]
                else
                
                end
                if recipe.energyRequired then
                    energy = energy + 0.2*recipe.energy_required
                end
                if recipe.result_count then
                    energy = energy * recipe.result_count
                end
            end
        else
        end
        
        --result = "night-vision-equipment"
        recipe.energy_required = energy
        recipe.processed = true
    end
end

for i, recipe in pairs (data.raw["recipe"]) do
    if (recipe.category == nil) or (recipe.category == "advanced-crafting") then
        process(recipe)
    end
end

for i, recipe in pairs (data.raw["recipe"]) do
    recipe.processed = nil
end
Last edited by Ranakastrasz on Sat Oct 03, 2015 5:31 pm, edited 1 time in total.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Recursive Prototype alteration

Post by orzelek »

I'm not sure why it breaks finally but it has a type issue.

You are calling same function with either actual recipe table or giving it an ingredient as recipe table which is bound to break in weird way.

Recursive call would need to be like this:

Code: Select all

process(data.raw.recipe[ingredient[1])
You'll need to make sure first that recipe for it actually exists ofc.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Recursive Prototype alteration

Post by Ranakastrasz »

Oh, Ofc.
I forgot to take the ingredient and figure out it's source recipe. I think....

I don't think I can actually do that without another massive loop.... Unless the game already has something for that, like what determines the list of ingredients when crafting something complex.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Recursive Prototype alteration

Post by orzelek »

Ranakastrasz wrote:Oh, Ofc.
I forgot to take the ingredient and figure out it's source recipe. I think....

I don't think I can actually do that without another massive loop.... Unless the game already has something for that, like what determines the list of ingredients when crafting something complex.
The line I wrote should try to access recipe for making item in question. I think. If there is no recipe for it should return null.
Someone more versed with tables might help.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Recursive Prototype alteration

Post by Adil »

Well, you could describe in words what do you expect from this function.

The primitive debugging may be done by inserting print() calls in code. (Default lua print not alias to game.player.print ). That function writes to stdout. That means if you launch factorio with command line, it will print there. Or you can divert the output to file.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Recursive Prototype alteration

Post by Ranakastrasz »

So far as I can tell that line does work as expected, but I haven't added debug messages as such.


The idea was to see if I could set crafting time of recipes to be based entirely on the complexity, being complexity and count of ingrendients. Additionally, if the ingredients themselves were complex, then I wanted an extra penalty.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Recursive Prototype alteration

Post by Adil »

Well, didn't orzelek code solve the problem?
orzelek wrote:

Code: Select all

process(data.raw.recipe[ingredient[1])
Ultimately:

Code: Select all

--process(ingredient) -- This here
local recip=data.raw.recipe[ingredient[1]];
if recip and ((recip.category == nil) or (recip.category == "advanced-crafting")) then
     process(recip)
     --add complexity penalty here
end
Surely, Yuokitani mods with his "shm-bm-fm-wm-3" recipes are beyond the scope, but all vanilla recipes except for oil will be affected.
Apart from this prior knowledge there's no simple way of saying which items comes from where, you'd have to explicitly create the table of item-recipe pairs first.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Recursive Prototype alteration

Post by Ranakastrasz »

Yes, that works.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Post Reply

Return to “Modding help”