[0.12.1] Mods' on_load event called at the wrong time
Posted: Wed Jul 29, 2015 3:49 am
In version 0.12.1 (didn't test with 0.12.0), mods' on_load events are called when the user save a game, not when the user load it.
Please see the attached (test) mod
You would expect to see oninit(), followed by onload(), then oninitialtick(). However, onload() won't be called until you actually save the game.
This represents a problem whenever mods want to initialize data on game loading. Workaround: perform on-load tasks during the initial tick.
Please see the attached (test) mod
Code: Select all
require "defines"
-----------------------------------------------------------
-- utility functions
-----------------------------------------------------------
function print(s)
for index, player in pairs(game.players) do
if(player.valid) then
player.print(s);
end;
end
end
game.on_init(function(event)
print("oninit()");
end);
game.on_load(function(event)
print("onload()");
end);
game.on_event(defines.events.on_tick, function(event)
print("initial tick");
game.on_event(defines.events.on_tick, nil);
end);
This represents a problem whenever mods want to initialize data on game loading. Workaround: perform on-load tasks during the initial tick.