I have a mod which wishes to change the game.map_settings values, so I seemingly need to do this after the simulation has started. I was unable to find an event that description that fit the description of "run once on simulation start".
Is there an event I can use for run-once code and avoid piggy-backing on to another event that is called more than once?
Is there an event type for on simulation start?
Re: Is there an event type for on simulation start?
Haven't tried, but I believe this should work:
on_init(f)
Register a callback to be run on mod init. This is called once when a new save game is created or once when a save file is loaded that previously didn't contain the mod. This is always called before other event handlers and is meant for setting up initial values that a mod will use for its lifetime.
Parameters
f :: function(): The function to call. Passing nil will unregister the handler.
Code: Select all
script.on_init(function()
game.map_settings.enemy_evolution.destroy_factor = 1
end)
Register a callback to be run on mod init. This is called once when a new save game is created or once when a save file is loaded that previously didn't contain the mod. This is always called before other event handlers and is meant for setting up initial values that a mod will use for its lifetime.
Parameters
f :: function(): The function to call. Passing nil will unregister the handler.
Re: Is there an event type for on simulation start?
Mooncat's solution worked, thank you for the help.
Re: Is there an event type for on simulation start?
This only ever runs once; what if you need something like "always run X code once every time a map is loaded"? on_load cannot safely change the game state, and I see no other hook. I need this for ensuring certain map settings are the correct values in case they have been changed by a command or other mod since my mod was first installed.Mooncat wrote:Haven't tried, but I believe this should work:on_init(f)Code: Select all
script.on_init(function() game.map_settings.enemy_evolution.destroy_factor = 1 end)
Register a callback to be run on mod init. This is called once when a new save game is created or once when a save file is loaded that previously didn't contain the mod. This is always called before other event handlers and is meant for setting up initial values that a mod will use for its lifetime.
Parameters
f :: function(): The function to call. Passing nil will unregister the handler.