This is a follow-up on the bug discussed here: https://mods.factorio.com/mod/research- ... 000dfca76c
- What did I do:
Start a game with two mods installed/unpacked/enabled - https://mods.factorio.com/mod/Will-o-the-Wisps_updated and https://mods.factorio.com/mod/research- ... -new-thing
Other mods were enabled as well at the time, but none that should interfere with this sequence afaik.
First mod (Will-o-the-Wisps_updated) has code like this:Second one has code like this:Code: Select all
local function wisp_force_init(name) print(('---------- wisp_force_init: %s'):format(name)) wisps = game.create_force(name) ... end script.on_init(function() ... wisp_force_init('wisp') wisp_force_init('wisp_attack') ... end
Code: Select all
script.on_nth_tick(60, function(event) print('---------- nth_tick') ... end) script.on_event(defines.events.on_force_created, function(event) print(('---------- on_force_created hook: %s'):format(event.force.name)) ... end)
- Expected result:
When starting new game, I'll see output like this in stdout from running factorio game (among other stuff):
This is expected because on_force_created event is explicitly documented as "Called when a new force is created using game.create_force()"Code: Select all
---------- wisp_force_init: wisp ---------- on_force_created hook: wisp ---------- wisp_force_init: wisp_attack ---------- on_force_created hook: wisp_attack ---------- nth_tick
game.create_force() is called from on_init(), so event hook should presumably be called sometime after that, before nth_tick.
This is not what happens. - Actual result:
Following sequence of events is observed instead:I.e. contrary to documentation, on_force_created event is never fired when game.create_force() is called.Code: Select all
---------- wisp_force_init: wisp ---------- wisp_force_init: wisp_attack ---------- nth_tick ---------- nth_tick ...
I didn't try it in complete isolation (i.e. creating only trivial 10-liner mods with only code above), but given how early it happens and that nothing else interferes with events in these two mods, con't see any reason why it should break here either.
Some earlier thread on this forum that was able to find - viewtopic.php?f=7&t=39906 - seem to explicitly suggest that it should work in this exact situation between two mods, at least in 0.14.x.
If it should not fire from on_init sequence, I think it'd be best to add that to lua-api documentation, as that's where I think forces are usually initialized in mods, so it's a very important limitation that is worth mentioning.