Entry point for registering event handlers. It is accessible through the global object named script
.
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 the specified event(s). |
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, data) | Raise an event. |
raise_console_chat(table) | Raises on_console_chat |
raise_player_crafted_item(table) | Raises on_player_crafted_item |
raise_player_fast_transferred(table) | Raises on_player_fast_transferred |
raise_biter_base_built(table) | Raises on_biter_base_built |
raise_market_item_purchased(table) | Raises on_market_item_purchased |
raise_script_built(table) | Raises script_raised_built |
raise_script_destroy(table) | Raises script_raised_destroy |
raise_script_revive(table) | Raises script_raised_revive |
raise_script_set_tiles(table) | Raises script_raised_set_tiles |
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] | A dictionary listing the names of all currently active mods and mapping them to their version. |
object_name :: string [R] | This object's 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.
nil
will 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.
nil
will unregister the handler.Register a handler to run on the specified event(s).
Register a handler to run every nth tick(s). When the game is on tick 0 it will trigger all registered handlers.
nil
as the only
parameter will unregister all nth-tick handlers.nil
will unregister the handler for
the provided ticks.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.
nil
if none are defined.Raise an event. Only events generated with LuaBootstrap::generate_event_name and the following can be raised:
Raises on_console_chat
Raises on_player_crafted_item
Raises on_player_fast_transferred
Raises on_biter_base_built
Raises on_market_item_purchased
Raises script_raised_built
Raises script_raised_destroy
Raises script_raised_revive
Raises 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:
A dictionary listing the names of all currently active mods and mapping them to their version.
for name, version in pairs(script.active_mods) do
game.print(name .. " version " .. version)
end
This object's name.