Page 1 of 1

Why is on_configuration_changed not running?

Posted: Thu Feb 01, 2018 7:30 am
by quyxkh
I'm getting a very weird symptom: a scenario map's on_configuration_changed does not run if loaded when its mod is missing, and it's got something to do with remote interfaces. I've included a fairly minimal reproducer, I'm posting here on the theory that I must be doing something wrong. The o-c-c function is called properly for istm any change that doesn't involve removing that interface.

Here's the entirety of the mod's control.lua:

Code: Select all

function testocc_interface()
	print('testocc-interface')
end
remote.add_interface('testocc',{t_i=testocc_interface})
and the non-scaffolding parts of the attached scenario's control.lua:

Code: Select all

function configuration_changed(ccdata)
    print(serpent.block(ccdata or 'o-c-c from on-init'))
    do local _=remote.interfaces.testocc or {}
        global.use_testocc_ti = _.t_i or false
        print(_.t_i or false)
        end
    end
function conditionalhooks()
    if global.use_testocc_ti then
        for x=1,#player do
            remote.call('testocc','t_i'
                    ,{player_index=x})
            end
    else
        on('player_left_game')
        end
    end
for k,v in next,_G do npg[k]=true end

use_testocc_ti = {} -- placeholder
player={}
on('configuration_changed',configuration_changed)
on('load',function()
    for k,v in next,global do 
        print('Global "'..k..'" restored')
        _G[k]=v end
    conditionalhooks()
    end)

on('init',function(...)
    for k,v in next,_G do if not npg[k] then
        print('Global "'..k..'" persisted')
        global[k]=v end end
    configuration_changed()
    -- don't know c-c changing the lua globals is ok so just reload from map globals 
    for k,v in next,global do _G[k]=v end
    conditionalhooks()
    end)

Re: Why is on_configuration_changed not running?

Posted: Fri Feb 02, 2018 3:52 am
by Rseding91

Code: Select all

on('init',function(...) ...

... why? Why obscure what's perfectly clear logic that 95%+ of the mods do and any beginner can find documentation on behind functions like this?

Code: Select all

script.on_init(function(...) ... end)
is perfectly clear what it's doing and anyone new to Factorio modding will immediately know what it does because that's how the official documentation says to do it.

Re: Why is on_configuration_changed not running?

Posted: Fri Feb 02, 2018 5:19 am
by quyxkh
... yah, I thought that might be a distraction, so I made and have attached a really minimalized test-case.
digression
I've attached a scenario-only mod, and a service mod that provides a remote-call interface. To reproduce what I'm looking at,

1. Run with only the test-o-c-c-scenario mod (and any others except the other attached one), and play and save the map with the test-o-c-c-scenario/test-o-c-c scenario. It prints messages to the console, those might be helpful.

2. Bang on mod presence/version changes (*including* the attached test-o-c-c-service) you want, you can see the scenario's o-c-c- runs fine.

3. Save the map after loading it with the test-o-c-c-service mod present. Make any changes you want except removing the test-o-c-c-service mod, this save's o-c-c still runs fine, you can see the serpent.block printout of the args on the console.

4. Reload the save from step 3 without the test-o-c-c-service mod.

There's the part I don't understand: loading fails with an error in on_load, but it appears on_configuration_changed never ran.
service control.lua
scenario control.lua

Re: Why is on_configuration_changed not running?

Posted: Fri Feb 02, 2018 11:21 am
by darkfrei
Rseding91 wrote:

Code: Select all

on('init',function(...) ...
... why? Why obscure what's perfectly clear logic that 95%+ of the mods do and any beginner can find documentation on behind functions like this?

Code: Select all

script.on_init(function(...) ... end)
is perfectly clear what it's doing and anyone new to Factorio modding will immediately know what it does because that's how the official documentation says to do it.
What if I want to call "on_init" twice? Is it possible to register every "on_init" calling?

Re: Why is on_configuration_changed not running?

Posted: Sun Feb 04, 2018 10:42 pm
by quyxkh
Well, the problem was that I somehow got it in my head that on_configuration_changed runs before on_load, which doesn't match any version of docs or reality that I can find now. on_configuration_changed runs after on_load.

Re: Why is on_configuration_changed not running?

Posted: Mon Feb 05, 2018 9:52 am
by bobingabout
darkfrei wrote:
Rseding91 wrote:

Code: Select all

on('init',function(...) ...
... why? Why obscure what's perfectly clear logic that 95%+ of the mods do and any beginner can find documentation on behind functions like this?

Code: Select all

script.on_init(function(...) ... end)
is perfectly clear what it's doing and anyone new to Factorio modding will immediately know what it does because that's how the official documentation says to do it.
What if I want to call "on_init" twice? Is it possible to register every "on_init" calling?
I've tried that before, the second call over-writes the first. There can only be one on_init.

Re: Why is on_configuration_changed not running?

Posted: Tue Feb 13, 2018 12:16 pm
by chrisgbk
darkfrei wrote:
Rseding91 wrote:

Code: Select all

on('init',function(...) ...
... why? Why obscure what's perfectly clear logic that 95%+ of the mods do and any beginner can find documentation on behind functions like this?

Code: Select all

script.on_init(function(...) ... end)
is perfectly clear what it's doing and anyone new to Factorio modding will immediately know what it does because that's how the official documentation says to do it.
What if I want to call "on_init" twice? Is it possible to register every "on_init" calling?
The accepted method is to register a single on_init stub that calls every on_init function you want called.

Code: Select all

script.on_init(function()
  my_init()
  some_other_init()
end)

Re: Why is on_configuration_changed not running?

Posted: Tue Feb 13, 2018 7:07 pm
by darkfrei
chrisgbk wrote:The accepted method is to register a single on_init stub that calls every on_init function you want called.

Code: Select all

script.on_init(function()
  my_init()
  some_other_init()
end)
It would be nice to have every script function in vanilla like this:

Code: Select all

script.on_init(function()
  for i, on_init_handler in pairs (on_init_handlers) do
    on_init_handler() -- all on_init functions in control.lua
  end
end)
So, if you must register your function in the list of functions.