Page 1 of 1

Is there an event type for on simulation start?

Posted: Thu Jul 13, 2017 4:32 am
by admo
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?

Re: Is there an event type for on simulation start?

Posted: Thu Jul 13, 2017 6:27 am
by Mooncat
Haven't tried, but I believe this should work:

Code: Select all

script.on_init(function()
    game.map_settings.enemy_evolution.destroy_factor = 1
end)
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.

Re: Is there an event type for on simulation start?

Posted: Thu Jul 13, 2017 1:21 pm
by admo
Mooncat's solution worked, thank you for the help.

Re: Is there an event type for on simulation start?

Posted: Sun Jul 16, 2017 5:00 am
by Reika
Mooncat wrote:Haven't tried, but I believe this should work:

Code: Select all

script.on_init(function()
    game.map_settings.enemy_evolution.destroy_factor = 1
end)
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.
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.