Code: Select all
script.on_event(defines.events.on_tick, function(event)
-- some code here
script.on_event(defines.events.on_tick, nil)
end)
The on_init event is the correct way to initialize variables your mod will be using for its lifetime. It's called when a new save file is created with your mod or when a save file is loaded with your mod when it didn't previously contain your mod.
The on_configuration_changed event is the correct way to detect mod additions, removals, or changes. It will be called any time any mods are changed (including the base game mods). Read: this includes any change to the mod protoype files - if the result crc from processing the mod is different it will be detected and the event will be fired. Even adding a single newline to any prototype file will trigger it.
The on_load event is ONLY meant for the 3 things listed on the docs page. If you do anything else in that event then you're almost certainly making an error.
If you have any questions please let me know and I'll do my best to answer them. Additionally the data lifecycle page may be helpful to understand in what order the game does startup and new game/load game processing