Page 1 of 1

Recursive Prototype alteration: Resolved

Posted: Thu Oct 01, 2015 5:01 pm
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

Re: Recursive Prototype alteration

Posted: Thu Oct 01, 2015 5:58 pm
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.

Re: Recursive Prototype alteration

Posted: Thu Oct 01, 2015 6:49 pm
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.

Re: Recursive Prototype alteration

Posted: Thu Oct 01, 2015 8:27 pm
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.

Re: Recursive Prototype alteration

Posted: Sat Oct 03, 2015 8:06 am
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.

Re: Recursive Prototype alteration

Posted: Sat Oct 03, 2015 10:41 am
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.

Re: Recursive Prototype alteration

Posted: Sat Oct 03, 2015 11:34 am
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.

Re: Recursive Prototype alteration

Posted: Sat Oct 03, 2015 5:31 pm
by Ranakastrasz
Yes, that works.