Is there an event type for on simulation start?

Place to get help with not working mods / modding interface.
Post Reply
admo
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 1:07 am
Contact:

Is there an event type for on simulation start?

Post 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?

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

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

Post 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.

admo
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 1:07 am
Contact:

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

Post by admo »

Mooncat's solution worked, thank you for the help.

User avatar
Reika
Filter Inserter
Filter Inserter
Posts: 582
Joined: Tue May 19, 2015 1:56 am
Contact:

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

Post 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.
Image

Post Reply

Return to “Modding help”