Page 1 of 1
Help me, in my mod“script.on_init”not run
Posted: Tue Oct 29, 2024 7:46 am
by sdgmlj
It only runs when a new game is created and does not run when reading saved files
To verify this issue, I deleted all the content in the mod, but kept the following content in "control. lua":
script.on_init(function()
for i, player in pairs(game.players) do
player.print({"message.message"})
end
end)
When reading the archive, it still does not run
Re: Help me, in my mod“script.on_init”not run
Posted: Tue Oct 29, 2024 8:35 am
by Stringweasel
This is intended behaviour. If you look at the
Life Cycle you can see
on_init is only run when a new game is created.
When an existing save is loaded then
on_load is called instead. However, please keep in mind that for 99.9% of cases mods don't have to do anything in this event, and it's also very easy to cause desyncs. For 99.9% of cases you'd want to use
on_configuration_changed instead.
Re: Help me, in my mod“script.on_init”not run
Posted: Wed Oct 30, 2024 9:04 am
by sdgmlj
Stringweasel wrote: Tue Oct 29, 2024 8:35 am
This is intended behaviour. If you look at the
Life Cycle you can see
on_init is only run when a new game is created.
When an existing save is loaded then
on_load is called instead. However, please keep in mind that for 99.9% of cases mods don't have to do anything in this event, and it's also very easy to cause desyncs. For 99.9% of cases you'd want to use
on_configuration_changed instead.
Thanks