DaCyclops / GDIW

Factorio Mod : GDIW - Gah!DarnItWater! A Factorio mod for those people who keep getting annoyed at water....
MIT License
3 stars 5 forks source link

Added nill check that occured with pyan i think #23

Closed daanroeterink closed 5 years ago

daanroeterink commented 5 years ago

i dont know if this is correct lua but this seems to work with me.

DaCyclops commented 5 years ago

Yeah, you have basically mucked with a sorting command. it likely is breaking something by doing that. the function works by passing two entries from the input table as "a" and "b" and then uses the function to determine the order. if for some reason it isnt passing an a or b, there might be something fucked with earlier code, or with the other mod's code.

Could you actually detail what Py mod your using that is causing it, so I can investigate?

daanroeterink commented 5 years ago

Thanks for responding. I did some more digging.

I found out that the recipes that allowed one of the recipes to be nil are being changed by the py mods. Like on this line: RECIPE("lithium-peroxide"):rem_ing("water"):add_ing({type = "fluid", name = "lithia-water", amount = 300})

--(( Coal Processing 3 ))--
RECIPE {
    type = "recipe",
    name = "lithium-peroxide",
    category = "chemistry",
    enabled = false,
    energy_required = 5,
    ingredients = {
        --{type="fluid", name="lithia-water", amount=30},
        {type = "fluid", name = "water", amount = 300},
        {type = "fluid", name = "hydrogen-peroxide", amount = 100}
    },
    results = {
        {type = "item", name = "lithium-peroxide", amount = 5}
    }
}:add_unlock("coal-processing-3")

I found out by error logging the other not nil variable in the sorting function. this logged "lithia-water" as the not nil variable. I guess it should the nil variable should have been hydrogen-perioxide in above example. If a comment out the replace line it works, and errors on a other recipe. About 5 in total.

These rem_ing and add_ing remove and add ingredients to recipes the functions are defined in the std_lib mod https://mods.factorio.com/mod/stdlib

Maybe this somehow gets in a state where the ingredient is removed by not yet added while GDIW is doing its magic?

I tried to add pyanodon to the dependencies so GDIW is loaded after all recipe changes have been done but this didn't work either. I am still very new to Factorio modding so that's all i could think off

I attached my mod list and save game (for easier syncing the mods maybe)? PyanodonAngelsBobs0.17.zip

mod-list.zip

Edit:

So there are 4 recipes where it goes wrong: brokenrecipes.zip

They either have 2 fluid ingredients at the start and then one of those fluid ingredient is changed to another fluid

Or they only have 1 fluid ingredient at the start and a new fluid ingredient is added. through add_ing.

RECIPE("lithium-peroxide"):rem_ing("water"):add_ing({type = "fluid", name = "lithia-water", amount = 300})

Above line will set nil values in the sorting

RECIPE("lithium-peroxide"):rep_ing("water", "lithia-water")

this works fine

DaCyclops commented 5 years ago

Looking at what you have found, im thinking it might be having an issue with identical-named ingredients. Or however it "deletes" an ingredient causing issues.

Im not going to merge this pull, only because Im refactoring the code due to this - moving the sorting function out as a proper function, so we can update all 6 uses in one place. Also adding a Nil check (from my checking online, a sort function should return false if there is an issue)

Im also gonna add every Py mod as a hidden optional dependency, because they just seem not to like me.