on_init(f) | Register a callback to be run on mod init. |
on_load(f) | Register a function to be run on module load. |
on_configuration_changed(f) | Register a function to be run when mod configuration changes. |
on_event(event, f) | Register a handler to run on event or events. |
generate_event_name() → uint | Generate a new, unique event ID. |
Entry point for registering event handlers. It is accessible through the global object named script
.
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.
Register a function to be run on module load. This is called every time a save file is loaded *except* for the instance when a mod is loaded into a save file that it previously wasn't part of. Additionally this is called when connecting to any other game in a multiplayer session and should never change the game state.
This is meant for 3 specific reasons and only 3:
In all other instances the LuaBootstrap::on_init, LuaBootstrap::on_configuration_changed or migration scripts should be used. Doing any other logic when loading a save file can break the replay and cause desync issues if the mod is used in multiplayer.
nil
will unregister the handler.Register a function to be run when mod configuration changes. This is called any time the game version changes and any time mod versions change including adding or removing mods.
nil
will unregister the handler.Register a handler to run on event or events.
name
(of type defines.events) specifying the name
of the event it was called to handle, and tick
that specifies when the event was created. This table will
also contain other fields, depending on the type of the event. See
the list of Factorio events for a listing of these additional fields.Generate a new, unique event ID.