[0.17.68] script.on_configuration_changed happens too soon?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Mylon
Filter Inserter
Filter Inserter
Posts: 513
Joined: Sun Oct 23, 2016 11:42 pm
Contact:

[0.17.68] script.on_configuration_changed happens too soon?

Post by Mylon »

So I'm using script.on_configuration_changed to unlock recipes that should be unlocked if the player is adding this mod to a game in progress. I use the following function:

Code: Select all

function retroactivate()
    global.MTBF_meddling = global.MTBF_meddling or {}
    --log("Performing migration.")
    game.print("Doing migration 1")
    for _, force in pairs(game.forces) do
        for __, tech in pairs(force.technologies) do
            if tech.researched then
                for ___, effect in pairs(tech.effects) do
                    if effect.type == "unlock-recipe" and string.find(effect.recipe, "broken-") then
                        game.print("Doing migration 2")
                        force.recipes[effect.recipe].enabled = true
                        force.recipes["robot-control-module"].enabled = true
                        force.recipes["robot-powercell"].enabled = true
                        force.recipes[string.gsub(effect.recipe, "broken%-", "disassemble-")].enabled = true
                    end
                end
            end
        end
    end
end
When I load the save, the matching print statements fire. But the expected recipes are not unlocked! If I copy/paste from the first for loop to the matching end and paste it as a command, the recipes unlock as expected.

The running mods list are as follows:

Code: Select all

72.872 Checksum for script __Assembler_Assay__/control.lua: 550528542
  72.898 Checksum for script __BeltUpgrader__/control.lua: 1699357547
  72.914 Checksum for script __Bot_Servicing__/control.lua: 770765553
  72.916 Checksum for script __Concreep__/control.lua: 2984749389
  72.926 Checksum for script __Dirt_Path__/control.lua: 1160991668
  72.953 Checksum for script __Fill4Me__/control.lua: 89059952
  72.954 Checksum for script __MoreAchievements__/control.lua: 3879118096
  72.956 Checksum for script __boblogistics__/control.lua: 3426676619
The only mods here that aren't mine are Bob's Logistics and Fill4Me.
Last edited by Mylon on Fri Sep 06, 2019 1:34 am, edited 2 times in total.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.17.68] script.on_configuration_changed happens too soon?

Post by Rseding91 »

Thanks for the report however I don't see anything that's a bug here. The event happens after the game is loaded directly before the next tick happens; everything is loaded and ready to run.

Unless you can show there's some logic error in the game it just seems like you have another mod which is changing recipe enabled/disabled status maybe?
If you want to get ahold of me I'm almost always on Discord.

User avatar
Mylon
Filter Inserter
Filter Inserter
Posts: 513
Joined: Sun Oct 23, 2016 11:42 pm
Contact:

Re: [0.17.68] script.on_configuration_changed happens too soon?

Post by Mylon »

Nevermind. Turns out Bobs mods was calling force.reset_technology_effects() and this was undoing my script. I added an event to respond to the reset and it works now.

Post Reply

Return to “Modding help”