Entry point for registering event handlers. It is accessible through the global object named
|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, filters)||Register a handler to run on event or events.|
|on_nth_tick(tick, f)||Register a handler to run every nth tick(s).|
|register_on_entity_destroyed(entity) → uint64||Registers an entity so that after it's destroyed on_entity_destroyed is called.|
|generate_event_name() → uint||Generate a new, unique event ID.|
|get_event_handler(event)||Find the event handler for an event.|
|get_event_order()||Gets the mod event order.|
|set_event_filter(event, filters)||Sets the filters for the given event.|
|get_event_filter(event) → table||Gets the filters for the given event.|
|raise_event(event, table)||Raise an event.|
|mod_name :: string [R]||The name of the mod from the environment this is used in.|
|level :: table [R]||Information about the currently running scenario/campaign/tutorial|
|active_mods :: dictionary string → string [R]||The active mods versions.|
|object_name :: string [R]||This objects name.|
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.
nilwill unregister the handler.
Register a function to be run when mod configuration changes. This is called any time the game version changes, prototypes change, startup mod settings change, and any time mod versions change including adding or removing mods.
nilwill 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
tickthat 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.
mod_nameadditionally to the above properties.
Register a handler to run every nth tick(s). When the game is on tick 0 it will trigger all registered handlers.
Registers an entity so that after it's destroyed on_entity_destroyed is called.
Generate a new, unique event ID.
Find the event handler for an event.
Gets the mod event order. type(string)
Gets the filters for the given event.
nilif none are defined.
Raise an event. Only events generated with LuaBootstrap::generate_event_name and the following can be raised: on_console_chat on_player_crafted_item on_player_fast_transferred on_biter_base_built on_market_item_purchased script_raised_built script_raised_destroy script_raised_revive script_raised_set_tiles
The name of the mod from the environment this is used in.
Information about the currently running scenario/campaign/tutorial
Table with the following fields:
The active mods versions. The keys are mod names, the values are the versions.
for name, version in pairs(script.active_mods) do
p.print(name .. " version " .. version)
This objects name.