Main toplevel type, provides access to most of the API though its members. An instance of LuaGameScript is available as the global object named game.
booleanbooleanfalseWhether players who are not admins can access all debug settings. Set this to false to disallow access to most debug settings for non-admins.
The following debug settings are always available to all players: "show-fps", "show-clock", "show-time-to-next-autosave", "show-detailed-info", "show-time-usage", "show-entity-time-usage", "show-gpu-time-usage", "show-sprite-counts", "show-particle-counts", "show-collector-navmesh-time-usage", "show-lua-object-statistics", "show-heat-buffer-info", "show-multiplayer-waiting-icon", "show-multiplayer-statistics", "show-multiplayer-server-name", "show-debug-info-in-tooltips", "show-resistances-in-tooltips-always", "hide-mod-guis", "show-tile-grid", "show-blueprint-grid", "show-intermediate-volume-of-working-sounds", "show-decorative-names", "allow-increased-zoom", "show-train-no-path-details", "show-entity-tick", "show-update-tick"
stringunknownfalseThe class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.
LuaPlayerunknowntrueThis property is only populated inside custom command handlers and when writing Lua console commands. Returns the player that is typing the command, nil in all other instances.
See LuaGameScript::players for accessing all players.
LuaCustomTable<uint32 | string, LuaPlayer>unknownfalseGet a table of all the players that currently exist. This sparse table allows you to find players by indexing it with either their name or index. Iterating this table with pairs() will provide the indexes as the keys. Iterating with ipairs() will not work at all.
If only a single player is required, LuaGameScript::get_player should be used instead, as it avoids the unnecessary overhead of passing the whole table to Lua.
MapSettingsunknownfalseThe currently active set of map settings. Even though this property is marked as read-only, the members of the dictionary that is returned can be modified mid-game.
This does not contain difficulty settings, use LuaGameScript::difficulty_settings instead.
DifficultySettingsunknownfalseThe currently active set of difficulty settings. Even though this property is marked as read-only, the members of the dictionary that is returned can be modified mid-game.
defines.difficultyunknownfalseCurrent scenario difficulty.
LuaCustomTable<uint32 | string, LuaForce>unknownfalseGet a table of all the forces that currently exist. This sparse table allows you to find forces by indexing it with either their name or index. Iterating this table with pairs() will provide the names as the keys. Iterating with ipairs() will not work at all.
booleanunknownfalseWhether a console command has been used.
LuaSimulationunknownfalseSimulation-related functions, or nil if the current game is not a simulation.
MapTickunknownfalseCurrent map tick.
MapTickunknownfalseThe number of ticks since this game was created using either "new game" or "new game from scenario". Notably, this number progresses even when the game is tick_paused.
This differs from LuaGameScript::tick in that creating a game from a scenario always starts with this value at 0, even if the scenario has its own level data where the tick has progressed past 0.
booleanbooleanfalseIf the tick has been paused. This means that entity update has been paused.
uint32uint32falseThe number of ticks to be run while the tick is paused.
When LuaGameScript::tick_paused is true, ticks_to_run behaves the following way: While this is > 0, the entity update is running normally and this value is decremented every tick. When this reaches 0, the game will pause again.
booleanunknownfalseTrue while the victory screen is shown.
booleanunknownfalseTrue after players finished the game and clicked "continue".
floatfloatfalseSpeed to update the map at. 1.0 is normal speed -- 60 UPS. Minimum value is 0.01.
LuaCustomTable<uint32 | string, LuaSurface>unknownfalseGet a table of all the surfaces that currently exist. This sparse table allows you to find surfaces by indexing it with either their name or index. Iterating this table with pairs() will provide the names as the keys. Iterating with ipairs() will not work at all.
LuaCustomTable<string, LuaPlanet>unknownfalseArray<LuaPlayer>unknownfalseThe players that are currently online.
This does *not* index using player index. See LuaPlayer::index on each player instance for the player index. This is primarily useful when you want to do some action against all online players.
LuaPermissionGroupsunknownfalseLuaCustomTable<uint32, string>unknownfalseArray of the names of all the backers that supported the game development early on. These are used as names for labs, locomotives, radars, roboports, and train stops.
MapGenSettingsunknownfalseThe default map gen settings for this save.
booleanbooleanfalseDetermines if enemy land mines are completely invisible or not.
booleanbooleanfalseTrue by default. Can be used to disable autosaving. Make sure to turn it back on soon after.
booleanbooleanfalseTrue by default. Can be used to disable the highlighting of resource patches when they are hovered on the map.
LuaTrainManagerunknownfalseArray<LuaRecord>unknownfalseRecords contained in the "game blueprints" tab of the blueprint library.
booleanbooleanfalseTrue by default. Can be used to prevent the game engine from printing certain messages.
booleanbooleanfalseIf the tips are allowed to be activated in this scenario, it is false by default.
Can't be modified in a simulation (menu screen, tips and tricks simulation, factoriopedia simulation etc.)
LuaGameScript.set_game_state{ game_finished?: boolean, player_won?: boolean, next_level?: string, can_continue?: boolean }
game.set_game_state{ game_finished=true }
takes_table: truetable_optional: falseSet scenario state. Any parameters not provided do not change the current state.
game_finished?: booleanplayer_won?: booleannext_level?: stringcan_continue?: booleanLuaGameScript.reset_game_state()
game.reset_game_state()
takes_table: falsetable_optional: falseReset scenario state (game_finished, player_won, etc.).
LuaGameScript.set_win_ending_info{ title: LocalisedString, message?: LocalisedString, bullet_points?: Array<LocalisedString>, final_message?: LocalisedString, image_path?: string }
game.set_win_ending_info{ title=title }
takes_table: truetable_optional: falseSet winning ending information for the current scenario.
title: LocalisedStringmessage?: LocalisedStringbullet_points?: Array<LocalisedString>final_message?: LocalisedStringimage_path?: stringLuaGameScript.set_lose_ending_info{ title: LocalisedString, message?: LocalisedString, bullet_points?: Array<LocalisedString>, final_message?: LocalisedString, image_path?: string }
game.set_lose_ending_info{ title=title }
takes_table: truetable_optional: falseSet losing ending information for the current scenario.
title: LocalisedStringmessage?: LocalisedStringbullet_points?: Array<LocalisedString>final_message?: LocalisedStringimage_path?: stringLuaGameScript.get_entity_by_tag(tag: string) -> LuaEntity?
game.get_entity_by_tag(tag)
takes_table: falsetable_optional: falseGets an entity by its name tag. Entity name tags can also be set in the entity "extra settings" GUI in the map editor.
tag: stringLuaEntity?LuaGameScript.show_message_dialog{ text: LocalisedString, image?: string, point_to?: GuiArrowSpecification, style?: string, wrapper_frame_style?: string }
game.show_message_dialog{ text=text }
takes_table: truetable_optional: falseShow an in-game message dialog.
Can only be used when the map contains exactly one player.
text: LocalisedString — What the dialog should sayimage?: string — Path to an image to show on the dialogpoint_to?: GuiArrowSpecification — If specified, dialog will show an arrow pointing to this place. When not specified, the arrow will point to the player's position. (Use point_to={type="nowhere"} to remove the arrow entirely.) The dialog itself will be placed near the arrow's target.style?: string — The gui style to use for this speech bubble. Must be of type speech_bubble.wrapper_frame_style?: string — Must be of type flow_style.LuaGameScript.is_demo() -> boolean
game.is_demo()
takes_table: falsetable_optional: falseIs this the demo version of Factorio?
booleanLuaGameScript.reload_script()
game.reload_script()
takes_table: falsetable_optional: falseForces a reload of the scenario script from the original scenario location.
This disables the replay if replay is enabled.
LuaGameScript.reload_mods()
game.reload_mods()
takes_table: falsetable_optional: falseForces a reload of all mods.
This will act like saving and loading from the mod(s) perspective.
This will do nothing if run in multiplayer.
This disables the replay if replay is enabled.
LuaGameScript.save_atlas()
game.save_atlas()
takes_table: falsetable_optional: falseSaves the current configuration of Atlas to a file. This will result in huge file containing all of the game graphics moved to as small space as possible.
Exists mainly for debugging reasons.
LuaGameScript.check_consistency()
game.check_consistency()
takes_table: falsetable_optional: falseRun internal consistency checks. Allegedly prints any errors it finds.
Exists mainly for debugging reasons.
LuaGameScript.regenerate_entity(entities: string | Array<string>)
game.regenerate_entity(entities)
takes_table: falsetable_optional: falseRegenerate autoplacement of some entities on all surfaces. This can be used to autoplace newly-added entities.
All specified entity prototypes must be autoplacable.
entities: string | Array<string> — Prototype names of entity or entities to autoplace.LuaGameScript.take_screenshot{ player?: PlayerIdentification, by_player?: PlayerIdentification, surface?: SurfaceIdentification, position?: MapPosition, resolution?: TilePosition, zoom?: double, path?: string, show_gui?: boolean, show_entity_info?: boolean, show_cursor_building_preview?: boolean, anti_alias?: boolean, hide_clouds?: boolean, hide_fog?: boolean, quality?: int32, allow_in_replay?: boolean, daytime?: double, water_tick?: uint32, force_render?: boolean }
game.take_screenshot{ player=player }
takes_table: truetable_optional: falseTake a screenshot of the game and save it to the script-output folder, located in the game's user data directory. The name of the image file can be specified via the path parameter.
If Factorio is running headless, this function will do nothing.
player?: PlayerIdentification — The player to focus on. Defaults to the local player.by_player?: PlayerIdentification — If defined, the screenshot will only be taken for this player.surface?: SurfaceIdentification — If defined, the screenshot will be taken on this surface.position?: MapPosition — If defined, the screenshot will be centered on this position. Otherwise, the screenshot will center on player.resolution?: TilePosition — The maximum allowed resolution is 16384x16384 (8192x8192 when anti_alias is true), but the maximum recommended resolution is 4096x4096 (resp. 2048x2048). The x value of the position is used as the width, the y value as the height.zoom?: double — The map zoom to take the screenshot at. Defaults to 1.path?: string — The name of the image file. It should include a file extension indicating the desired format. Supports .png, .jpg /.jpeg, .tga and .bmp. Providing a directory path (ex. "save/here/screenshot.png") will create the necessary folder structure in script-output. Defaults to "screenshot.png".show_gui?: boolean — Whether to include GUIs in the screenshot or not. Defaults to false.show_entity_info?: boolean — Whether to include entity info ("Alt mode") or not. Defaults to false.show_cursor_building_preview?: boolean — When true and when player is specified, the building preview for the item in the player's cursor will also be rendered. Defaults to false.anti_alias?: boolean — Whether to render in double resolution and downscale the result (including GUI). Defaults to false.hide_clouds?: boolean — If true cloud shadows on ground won't be rendered. Defaults to false.hide_fog?: boolean — If true fog effect and foreground space dust effect won't be rendered. Defaults to false.quality?: int32 — The .jpg render quality as a percentage (from 0% to 100% inclusive), if used. A lower value means a more compressed image. Defaults to 80.allow_in_replay?: boolean — Whether to save the screenshot even during replay playback. Defaults to false.daytime?: double — Overrides the current surface daytime for the duration of screenshot rendering.water_tick?: uint32 — Overrides the tick of water animation, if animated water is enabled.force_render?: boolean — Screenshot requests are processed in between game update and render. The game may skip rendering (ie. drop frames) if the previous frame has not finished rendering or the game simulation starts to fall below 60 updates per second. If force_render is set to true, the game won't drop frames and process the screenshot request at the end of the update in which the request was created. This is not honored on multiplayer clients that are catching up to server. Defaults to false.LuaGameScript.set_wait_for_screenshots_to_finish()
game.set_wait_for_screenshots_to_finish()
takes_table: falsetable_optional: falseForces the screenshot saving system to wait until all queued screenshots have been written to disk.
LuaGameScript.take_technology_screenshot{ path?: string, player: PlayerIdentification, selected_technology?: TechnologyID, skip_disabled?: boolean, quality?: int32 }
game.take_technology_screenshot{ player=player }
takes_table: truetable_optional: falseTake a screenshot of the technology screen and save it to the script-output folder, located in the game's user data directory. The name of the image file can be specified via the path parameter.
path?: string — The name of the image file. It should include a file extension indicating the desired format. Supports .png, .jpg /.jpeg, .tga and .bmp. Providing a directory path (ex. "save/here/screenshot.png") will create the necessary folder structure in script-output. Defaults to "technology-screenshot.png".player: PlayerIdentification — The screenshot will be taken for this player.selected_technology?: TechnologyID — The technology to highlight.skip_disabled?: boolean — If true, disabled technologies will be skipped. Their successors will be attached to the disabled technology's parents. Defaults to false.quality?: int32 — The .jpg render quality as a percentage (from 0% to 100% inclusive), if used. A lower value means a more compressed image. Defaults to 80.LuaGameScript.remove_offline_players(players?: Array<PlayerIdentification>)
game.remove_offline_players()
takes_table: falsetable_optional: falseRemove players who are currently not connected from the map.
players?: Array<PlayerIdentification> — List of players to remove. If not specified, remove all offline players.LuaGameScript.force_crc()
game.force_crc()
takes_table: falsetable_optional: falseForce a CRC check. Tells all peers to calculate their current CRC, which are then compared to each other. If a mismatch is detected, the game desyncs and some peers are forced to reconnect.
LuaGameScript.create_force(force: string) -> LuaForce
game.create_force(force)
takes_table: falsetable_optional: falseCreate a new force.
The game currently supports a maximum of 64 forces, including the three built-in forces. This means that a maximum of 61 new forces may be created. Force names must be unique.
force: string — Name of the new forceLuaForce — The force that was just createdLuaGameScript.merge_forces(source: ForceID, destination: ForceID)
game.merge_forces(source, destination)
takes_table: falsetable_optional: falseMarks two forces to be merged together. All players and entities in the source force will be reassigned to the target force. The source force will then be destroyed. Importantly, this does not merge technologies or bonuses, which are instead retained from the target force.
The three built-in forces (player, enemy and neutral) can't be destroyed, meaning they can't be used as the source argument to this function.
The source force is not removed until the end of the current tick, or if called during the on_forces_merging or on_forces_merged event, the end of the next tick.
source: ForceID — The force to remove.destination: ForceID — The force to reassign all entities to.LuaGameScript.create_surface(name: string, settings?: MapGenSettings) -> LuaSurface
game.create_surface(name, settings)
takes_table: falsetable_optional: falseCreate a new surface.
The game currently supports a maximum of 4 294 967 295 surfaces, including the default surface. Surface names must be unique.
name: string — Name of the new surface.settings?: MapGenSettings — Map generation settings.LuaSurface — The surface that was just created.LuaGameScript.server_save(name?: string)
game.server_save()
takes_table: falsetable_optional: falseInstruct the server to save the map. Only actually saves when in multiplayer.
name?: string — Save file name. If not specified, the currently running save is overwritten. If there is no current save, no save is made.LuaGameScript.auto_save(name?: string)
game.auto_save()
takes_table: falsetable_optional: falseInstruct the game to perform an auto-save.
Only the server will save in multiplayer. In single player a standard auto-save is triggered.
name?: string — The autosave name if any. Saves will be named _autosave-*name* when provided.LuaGameScript.delete_surface(surface: SurfaceIdentification) -> boolean
game.delete_surface(surface)
takes_table: falsetable_optional: falseDeletes the given surface and all entities on it if possible.
surface: SurfaceIdentification — The surface to be deleted. Currently the primary surface (1, 'nauvis') cannot be deleted.boolean — If the surface was queued to be deleted.LuaGameScript.disable_replay()
game.disable_replay()
takes_table: falsetable_optional: falseDisables replay saving for the current save file. Once done there's no way to re-enable replay saving for the save file without loading an old save.
LuaGameScript.print(message: LocalisedString, print_settings?: PrintSettings)
game.print(message, print_settings)
takes_table: falsetable_optional: falsePrint text to the chat console all players.
By default, messages that are identical to a message sent in the last 60 ticks are not printed again.
message: LocalisedStringprint_settings?: PrintSettingsLuaGameScript.create_random_generator(seed?: uint32) -> LuaRandomGenerator
game.create_random_generator()
takes_table: falsetable_optional: falseCreates a deterministic standalone random generator with the given seed or if a seed is not provided the initial map seed is used.
*Make sure* you actually want to use this over math.random(...) as this provides entirely different functionality over math.random(...).
seed?: uint32LuaRandomGeneratorLuaGameScript.play_sound(sound_specification: PlaySoundSpecification)
game.play_sound(sound_specification)
takes_table: falsetable_optional: falsePlay a sound for every player in the game.
The sound is not played if its location is not charted for that player.
sound_specification: PlaySoundSpecification — The sound to play.LuaGameScript.kick_player(player: PlayerIdentification, reason?: string)
game.kick_player(player, reason)
takes_table: falsetable_optional: falseKicks the given player from this multiplayer game. Does nothing if this is a single player game or if the player running this isn't an admin.
player: PlayerIdentification — The player to kick.reason?: string — The reason given if any.LuaGameScript.ban_player(player: PlayerIdentification | string, reason?: string)
game.ban_player(player, reason)
takes_table: falsetable_optional: falseBans the given player from this multiplayer game. Does nothing if this is a single player game of if the player running this isn't an admin.
player: PlayerIdentification | string — The player to ban.reason?: string — The reason given if any.LuaGameScript.unban_player(player: PlayerIdentification | string)
game.unban_player(player)
takes_table: falsetable_optional: falseUnbans the given player from this multiplayer game. Does nothing if this is a single player game of if the player running this isn't an admin.
player: PlayerIdentification | string — The player to unban.LuaGameScript.purge_player(player: PlayerIdentification)
game.purge_player(player)
takes_table: falsetable_optional: falsePurges the given players messages from the game. Does nothing if the player running this isn't an admin.
player: PlayerIdentification — The player to purge.LuaGameScript.mute_player(player: PlayerIdentification)
game.mute_player(player)
takes_table: falsetable_optional: falseMutes the given player. Does nothing if the player running this isn't an admin.
player: PlayerIdentification — The player to mute.LuaGameScript.unmute_player(player: PlayerIdentification)
game.unmute_player(player)
takes_table: falsetable_optional: falseUnmutes the given player. Does nothing if the player running this isn't an admin.
player: PlayerIdentification — The player to unmute.LuaGameScript.is_multiplayer() -> boolean
game.is_multiplayer()
takes_table: falsetable_optional: falseWhether the save is loaded as a multiplayer map.
booleanLuaGameScript.get_map_exchange_string() -> string
game.get_map_exchange_string()
takes_table: falsetable_optional: falseGets the map exchange string for the map generation settings that were used to create this map.
stringLuaGameScript.get_player(player: uint32 | string) -> LuaPlayer?
game.get_player(player)
takes_table: falsetable_optional: falseGets the given player or returns nil if no player is found.
player: uint32 | string — The player index or name.LuaPlayer?LuaGameScript.get_surface(surface: uint32 | string) -> LuaSurface?
game.get_surface(surface)
takes_table: falsetable_optional: falseGets the given surface or returns nil if no surface is found.
This is a shortcut for LuaGameScript::surfaces.
surface: uint32 | string — The surface index or name.LuaSurface?LuaGameScript.create_profiler(stopped?: boolean) -> LuaProfiler
game.create_profiler()
takes_table: falsetable_optional: falseCreates a LuaProfiler, which is used for measuring script performance.
LuaProfiler cannot be serialized.
stopped?: boolean — Create the timer stoppedLuaProfilerLuaGameScript.create_inventory(size: uint16, gui_title?: LocalisedString) -> LuaInventory
game.create_inventory(size, gui_title)
takes_table: falsetable_optional: falseCreates an inventory that is not owned by any game object.
It can be resized later with LuaInventory::resize.
Make sure to destroy it when you are done with it using LuaInventory::destroy.
size: uint16 — The number of slots the inventory initially has.gui_title?: LocalisedString — The title of the GUI that is shown when this inventory is opened.LuaInventoryLuaGameScript.get_script_inventories(mod?: string) -> Dict<string, Array<LuaInventory>>
game.get_script_inventories()
takes_table: falsetable_optional: falseGets the inventories created through LuaGameScript::create_inventory.
Inventories created through console commands will be owned by "core".
mod?: string — The mod whose inventories to get. If not provided all inventories are returned.Dict<string, Array<LuaInventory>> — A mapping of mod name to array of inventories owned by that mod.LuaGameScript.reset_time_played()
game.reset_time_played()
takes_table: falsetable_optional: falseResets the amount of time played for this map.
LuaGameScript.get_pollution_statistics(surface: SurfaceIdentification) -> LuaFlowStatistics
game.get_pollution_statistics(surface)
takes_table: falsetable_optional: falseThe pollution statistics for this the given surface.
surface: SurfaceIdentificationLuaFlowStatisticsLuaGameScript.get_vehicles{ unit_number?: uint32, force?: ForceID, surface?: SurfaceIdentification, type?: EntityID | Array<EntityID>, is_moving?: boolean, has_passenger?: boolean } -> Array<LuaEntity>
game.get_vehicles{ unit_number=unit_number }
takes_table: truetable_optional: falseReturns vehicles in game.
unit_number?: uint32force?: ForceIDsurface?: SurfaceIdentificationtype?: EntityID | Array<EntityID>is_moving?: booleanhas_passenger?: booleanArray<LuaEntity>LuaGameScript.get_entity_by_unit_number(unit_number: uint32) -> LuaEntity?
game.get_entity_by_unit_number(unit_number)
takes_table: falsetable_optional: falseReturns entity with a specified unit number or nil if entity with such number was not found or prototype does not have EntityPrototypeFlags::get-by-unit-number flag set.
unit_number: uint32LuaEntity?