| on_init(handler) | Register a function to be run on mod initialization. [...] | |
Register a function to be run on mod initialization. [...] | ||
| on_load(handler) | Register a function to be run on save load. [...] | |
Register a function to be run on save load. [...] | ||
| on_configuration_changed(handler) | Register a function to be run when mod configuration changes. [...] | |
Register a function to be run when mod configuration changes. [...] | ||
| on_event(event, handler, filters?) | Register a handler to run on the specified event(s). [...] | |
Register a handler to run on the specified event(s). [...] | ||
| on_nth_tick(tick, handler) | Register a handler to run every nth-tick(s). [...] | |
Register a handler to run every nth-tick(s). [...] | ||
| register_on_object_destroyed(object) new | → uint64, uint64, defines.target_type | Registers an object so that after it's destroyed, on_object_destroyed is called. [...] |
Registers an object so that after it's destroyed, on_object_destroyed is called. [...] | ||
| register_metatable(name, metatable) | Register a metatable to have linkage recorded and restored when saving/loading. [...] | |
Register a metatable to have linkage recorded and restored when saving/loading. [...] | ||
| generate_event_name() | → uint | Generate a new, unique event ID that can be used to raise custom events with LuaBootstrap::raise_event. |
Generate a new, unique event ID that can be used to raise custom events with LuaBootstrap::raise_event. | ||
| get_event_handler(event) | → function(EventData)? | Find the event handler for an event. |
Find the event handler for an event. | ||
| get_event_order() | → string | Gets the mod event order as a string. |
Gets the mod event order as a string. | ||
| set_event_filter(event, filters?) | Sets the filters for the given event. [...] | |
Sets the filters for the given event. [...] | ||
| get_event_filter(event) | → EventFilter? | Gets the filters for the given event. |
Gets the filters for the given event. | ||
| raise_event(event, data) changed | Raise an event. [...] | |
Raise an event. [...] | ||
| raise_console_chat{player_index=…, message=…} | ||
| raise_player_crafted_item{item_stack=…, player_index=…, recipe=…} changed | ||
| raise_player_fast_transferred{player_index=…, entity=…, from_player=…, is_split=…} | ||
| raise_biter_base_built{entity=…} | ||
| raise_market_item_purchased{player_index=…, market=…, offer_index=…, count=…} | ||
| raise_script_built{entity=…} | ||
| raise_script_destroy{entity=…} | ||
| raise_script_revive{entity=…, tags?=…} | ||
| raise_script_teleported{entity=…, old_surface_index=…, old_position=…} | ||
| raise_script_set_tiles{surface_index=…, tiles=…} | ||
| mod_name | :: R string | The name of the mod from the environment this is used in. |
The name of the mod from the environment this is used in. | ||
| level | :: R table | Information about the currently running scenario/campaign/tutorial. |
Information about the currently running scenario/campaign/tutorial. | ||
| active_mods | :: R dictionary[string → string] | A dictionary listing the names of all currently active mods and mapping them to their version. |
A dictionary listing the names of all currently active mods and mapping them to their version. | ||
| feature_flags new | :: R table | A dictionary of feature flags mapping to whether they are enabled. |
A dictionary of feature flags mapping to whether they are enabled. | ||
| object_name | :: R string | The class name of this object. [...] |
The class name of this object. [...] | ||

| handler | :: function() or nil | The handler for this event. Passing |
The handler for this event. Passing | ||
-- Initialize a `players` table in `storage` for later use
script.on_init(function()
storage.players = {}
end)

| handler | :: function() or nil | The handler for this event. Passing |
The handler for this event. Passing | ||

| handler | :: function(ConfigurationChangedData) or nil | The handler for this event. Passing |
The handler for this event. Passing | ||

| event | :: defines.events or string or array[defines.events or string] | The event(s) or custom-input to invoke the handler on. |
The event(s) or custom-input to invoke the handler on. | ||
| handler | :: function(EventData) or nil | The handler for this event. Passing |
The handler for this event. Passing | ||
| filters | :: EventFilter? | The filters for this event. Can only be used when registering for individual events. |
The filters for this event. Can only be used when registering for individual events. | ||
-- Register for the on_tick event to print the current tick to console each tick
script.on_event(defines.events.on_tick,
function(event) game.print(event.tick) end)
-- Register for the on_built_entity event, limiting it to only be received when a `"fast-inserter"` is built
script.on_event(defines.events.on_built_entity,
function(event) game.print("Gotta go fast!") end,
{{filter = "name", name = "fast-inserter"}})

| tick | :: uint or array[uint] or nil | The nth-tick(s) to invoke the handler on. Passing |
The nth-tick(s) to invoke the handler on. Passing | ||
| handler | :: function(NthTickEventData) or nil | The handler to run. Passing |
The handler to run. Passing | ||

| object | :: LuaCustomChartTag or LuaEntity or LuaEquipment or LuaEquipmentGrid or LuaGuiElement or LuaItem or LuaLogisticCell or LuaLogisticNetwork or LuaLogisticSection or LuaPermissionGroup or LuaPlanet or LuaPlayer or LuaRailPath or LuaRenderObject or LuaSpacePlatform or LuaSurface or LuaTrain or LuaCommandable | The object to register. |
The object to register. | ||
| → uint64 | The registration number. It is used to identify the object in the on_object_destroyed event. |
| → uint64 | Useful identifier of the object if it has one. This identifier is specific to the object type, for example for trains it is the value LuaTrain::id. |
| → defines.target_type | Type of the target object. |



| event | :: uint | ID of the event to filter. |
ID of the event to filter. | ||
| filters | :: EventFilter? | The filters or |
The filters or | ||

| event | :: uint | ID of the event to get. |
ID of the event to get. | ||
| → EventFilter? | The filters or |

| event | :: uint or string | ID or name of the event to raise. |
ID or name of the event to raise. | ||
| data | :: table | Table with extra data that will be passed to the event handler. Any invalid LuaObjects will silently stop the event from being raised. |
Table with extra data that will be passed to the event handler. Any invalid LuaObjects will silently stop the event from being raised. | ||
-- Raise the on_console_chat event with the desired message 'from' the first player
local data = {player_index = 1, message = "Hello friends!"}
script.raise_event(defines.events.on_console_chat, data)

| player_index | :: uint | The player doing the chatting. |
The player doing the chatting. | ||
| message | :: string | The chat message to send. |
The chat message to send. | ||
| on_console_chat instantly | Raised with the provided arguments. |

| item_stack | :: LuaItemStack | The item that has been crafted. |
The item that has been crafted. | ||
| player_index | :: uint | The player doing the crafting. |
The player doing the crafting. | ||
| recipe | :: RecipeID | The recipe used to craft this item. |
The recipe used to craft this item. | ||
| on_player_crafted_item instantly | Raised with the provided arguments. |

| player_index | :: uint | The player transferred from or to. |
The player transferred from or to. | ||
| entity | :: LuaEntity | The entity transferred from or to. |
The entity transferred from or to. | ||
| from_player | :: boolean | Whether the transfer was from player to entity. If |
Whether the transfer was from player to entity. If | ||
| is_split | :: boolean | Whether the transfer was a split action (half stack). |
Whether the transfer was a split action (half stack). | ||
| on_player_fast_transferred instantly | Raised with the provided arguments. |

| entity | :: LuaEntity | The entity that was built. |
The entity that was built. | ||
| on_biter_base_built instantly | Raised with the provided arguments. |

| player_index | :: uint | The player who did the purchasing. |
The player who did the purchasing. | ||
| market | :: LuaEntity | The market entity. |
The market entity. | ||
| offer_index | :: uint | The index of the offer purchased. |
The index of the offer purchased. | ||
| count | :: uint | The amount of offers purchased. |
The amount of offers purchased. | ||
| on_market_item_purchased instantly | Raised with the provided arguments. |

| entity | :: LuaEntity | The entity that has been built. |
The entity that has been built. | ||
| script_raised_built instantly | Raised with the provided arguments. |

| entity | :: LuaEntity | The entity that was destroyed. |
The entity that was destroyed. | ||
| script_raised_destroy instantly | Raised with the provided arguments. |

| entity | :: LuaEntity | The entity that was revived. |
The entity that was revived. | ||
| tags | :: Tags? | The tags associated with this entity, if any. |
The tags associated with this entity, if any. | ||
| script_raised_revive instantly | Raised with the provided arguments. |

| entity | :: LuaEntity | The entity that was teleported. |
The entity that was teleported. | ||
| old_surface_index | :: uint8 | The entity's surface before the teleportation. |
The entity's surface before the teleportation. | ||
| old_position | :: MapPosition | The entity's position before the teleportation. |
The entity's position before the teleportation. | ||
| script_raised_teleported instantly | Raised with the provided arguments. |

| surface_index | :: uint | The surface whose tiles have been changed. |
The surface whose tiles have been changed. | ||
| tiles | :: array[Tile] | The tiles that have been changed. |
The tiles that have been changed. | ||
| script_raised_set_tiles instantly | Raised with the provided arguments. |


| is_simulation | :: boolean? | Is this level a simulation? (The main menu and 'Tips and tricks' use simulations) |
Is this level a simulation? (The main menu and 'Tips and tricks' use simulations) | ||
| is_tutorial | :: boolean? | Is this level a tutorial? |
Is this level a tutorial? | ||
| campaign_name | :: string? | The campaign name if any. |
The campaign name if any. | ||
| level_name | :: string | The level name. |
The level name. | ||
| mod_name | :: string? | The mod name if any. |
The mod name if any. | ||

-- This will print the names and versions of all active mods to the console.
for name, version in pairs(script.active_mods) do
game.print(name .. " version " .. version)
end
