### TechnologyUnit Full Configuration Example Source: https://lua-api.factorio.com/latest/types/TechnologyUnit.html A comprehensive example demonstrating the configuration of a TechnologyUnit, including count_formula, ingredients, and time. This setup is used for a space science pack research. ```lua unit = { count_formula = "2^(L-6)*1000", ingredients = { {"automation-science-pack", 1}, {"logistic-science-pack", 1}, {"chemical-science-pack", 1}, {"production-science-pack", 1}, {"utility-science-pack", 1}, {"space-science-pack", 1} }, time = 60 } ``` -------------------------------- ### Technology Prerequisites Example Source: https://lua-api.factorio.com/latest/prototypes/TechnologyPrototype.html Example showing how to define the 'prerequisites' for a technology. ```lua prerequisites = {"explosives", "military-2"} ``` -------------------------------- ### get_starting_area_radius Source: https://lua-api.factorio.com/latest/classes/LuaSurface.html Gets the starting area radius of this surface. ```APIDOC ## get_starting_area_radius ### Description Gets the starting area radius of this surface. ### Method `get_starting_area_radius()` ### Returns * **double** - The starting area radius. ``` -------------------------------- ### Technology Upgrade Example Source: https://lua-api.factorio.com/latest/prototypes/TechnologyPrototype.html Example demonstrating how to set the 'upgrade' property to true for a technology. ```lua { type = "technology", name = "physical-projectile-damage-2", [...] upgrade = true } ``` -------------------------------- ### carriages Source: https://lua-api.factorio.com/latest/classes/LuaTrain.html Gets an array of all rolling stock entities that make up the train, starting from the front. ```APIDOC ## carriages ### Description The rolling stocks this train is composed of, with the numbering starting at the front of the train. ### Property `carriages` (array[LuaEntity]) - Read-Only ``` -------------------------------- ### Example Item IDs Source: https://lua-api.factorio.com/latest/prototype-api.json These examples demonstrate the string format for referencing specific item prototypes by their unique names. ```lua "iron-plate" ``` ```lua "blueprint-book" ``` -------------------------------- ### get_bar Source: https://lua-api.factorio.com/latest/runtime-api.json Get the current bar. This is the index at which the red area starts. Only usable if this inventory supports having a bar. ```APIDOC ## get_bar ### Description Get the current bar. This is the index at which the red area starts. Only useable if this inventory supports having a bar. ### Return Values - **uint32** - The current bar index. ``` -------------------------------- ### Energy Specification Examples Source: https://lua-api.factorio.com/latest/types/Energy.html Demonstrates how to specify energy values using different units and multipliers. It shows examples for buffer capacity and input flow limit, and illustrates that '60W' and '1J' per second are equivalent power consumptions, though 'W' is the conventional unit for power. ```lua buffer_capacity = "5MJ" input_flow_limit = "300W" -- the following two lines result in the same power consumption: energy_usage = "60W" energy_usage = "1J" -- not recommended, Watt is convention for power ``` -------------------------------- ### Retrieve Existing Prototype Property Source: https://lua-api.factorio.com/latest/prototype-api.json Use `data.raw` to access and retrieve specific properties from existing prototypes. This example gets the maximum health of the wooden chest. ```lua -- get the max health of the wooden chest local health = data.raw["container"]["wooden-chest"].max_health ``` -------------------------------- ### Get Recipe Prototypes by Filter Source: https://lua-api.factorio.com/latest/runtime-api.json Retrieves recipe prototypes that match the specified filter. Use this to find recipes with specific energy requirements, for example, those that craft in less than half a second. ```lua -- Get every recipe prototype that takes less than half a second to craft (at crafting speed `1`). local prototypes = prototypes.get_recipe_filtered{{filter="energy", comparison="<", value=0.5}} ``` -------------------------------- ### Build Blueprint with Options Source: https://lua-api.factorio.com/latest/runtime-api.json Demonstrates how to build a blueprint using the `build_blueprint` method, with various options for build mode, player, direction, and force. ```lua -- build_blueprint(position, force, direction, build_mode, skip_fog_of_war, by_player, raise_built) -- Example usage: -- my_blueprint_record.build_blueprint({x=100, y=200}, defines.forces.player1, defines.direction.north, defines.build_mode.forced, true, Player(1), true) ``` -------------------------------- ### Iterating Through Active Mods Source: https://lua-api.factorio.com/latest/types/Mods.html This example demonstrates how to loop through all active mods and log their names and versions. It's useful for debugging or applying logic based on installed mods, as shown with the 'space-age' mod. ```lua -- when the only active mod is the space-age mod with version 2.0.7 -- then this logs for name, version in pairs(mods) do log(name .. " version " .. version) -- => space-age version 2.0.7 end ``` -------------------------------- ### Lamp Entity Configuration Example Source: https://lua-api.factorio.com/latest/prototypes/LampPrototype.html This is a comprehensive example of a lamp entity configuration in Factorio. It covers visual properties, energy usage, lighting, and signal-to-color mapping for circuit networks. ```lua { type = "lamp", name = "small-lamp", icon = "__base__/graphics/icons/small-lamp.png", flags = {"placeable-neutral", "player-creation"}, fast_replaceable_group = "lamp", minable = {mining_time = 0.1, result = "small-lamp"}, max_health = 100, corpse = "lamp-remnants", dying_explosion = "lamp-explosion", collision_box = {{-0.15, -0.15}, {0.15, 0.15}}, selection_box = {{-0.5, -0.5}, {0.5, 0.5}}, damaged_trigger_effect = hit_effects.entity(), impact_category = "glass", open_sound = {filename = "__base__/sound/open-close/electric-small-open.ogg", volume = 0.7}, close_sound = {filename = "__base__/sound/open-close/electric-small-close.ogg", volume = 0.7}, energy_source = { type = "electric", usage_priority = "lamp" }, energy_usage_per_tick = "5kW", darkness_for_all_lamps_on = 0.5, darkness_for_all_lamps_off = 0.3, light = {intensity = 0.9, size = 40, color = {1, 1, 0.75}}, light_when_colored = {intensity = 0, size = 6, color = {1, 1, 0.75}}, glow_size = 6, glow_color_intensity = 1, glow_render_mode = "multiplicative", picture_off = { layers = { { filename = "__base__/graphics/entity/small-lamp/lamp.png", priority = "high", width = 83, height = 70, shift = util.by_pixel(0.25,3), scale = 0.5 }, { filename = "__base__/graphics/entity/small-lamp/lamp-shadow.png", priority = "high", width = 76, height = 47, shift = util.by_pixel(4, 4.75), draw_as_shadow = true, scale = 0.5 } } }, picture_on = { filename = "__base__/graphics/entity/small-lamp/lamp-light.png", priority = "high", width = 90, height = 78, shift = util.by_pixel(0, -7), scale = 0.5 }, signal_to_color_mapping = { {type = "virtual", name = "signal-red", color = {1, 0, 0}}, {type = "virtual", name = "signal-green", color = {0, 1, 0}}, {type = "virtual", name = "signal-blue", color = {0, 0, 1}}, {type = "virtual", name = "signal-yellow", color = {1, 1, 0}}, {type = "virtual", name = "signal-pink", color = {1, 0, 1}}, {type = "virtual", name = "signal-cyan", color = {0, 1, 1}}, {type = "virtual", name = "signal-white", color = {1, 1, 1}}, {type = "virtual", name = "signal-grey", color = {0.5, 0.5, 0.5}}, {type = "virtual", name = "signal-black", color = {0, 0, 0}} }, default_red_signal = { type = "virtual", name = "signal-red" }, default_green_signal = { type = "virtual", name = "signal-green" }, default_blue_signal = { type = "virtual", name = "signal-blue" }, default_rgb_signal = { type = "virtual", name = "signal-white" }, circuit_connector = circuit_connector_definitions["lamp"], circuit_wire_max_distance = default_circuit_wire_max_distance } ``` -------------------------------- ### Filter Recipe Prototypes by Energy Cost Source: https://lua-api.factorio.com/latest/classes/LuaPrototypes.html Gets recipe prototypes that require a certain amount of energy to craft. The example finds recipes that take less than half a second to craft at crafting speed 1. ```Lua local prototypes = prototypes.get_recipe_filtered{{filter="energy", comparison="<", value=0.5}} ``` -------------------------------- ### Factorio Shortcut Definition Example Source: https://lua-api.factorio.com/latest/prototypes/ShortcutPrototype.html This example demonstrates how to define a custom shortcut for spawning an item, including its order, associated control input, technology unlock requirement, and icon paths. ```lua { type = "shortcut", name = "give-deconstruction-planner", order = "b[blueprints]-i[deconstruction-planner]", action = "spawn-item", localised_name = {"shortcut.make-deconstruction-planner"}, associated_control_input = "give-deconstruction-planner", technology_to_unlock = "construction-robotics", item_to_spawn = "deconstruction-planner", style = "red", icon = "__base__/graphics/icons/shortcut-toolbar/mip/new-deconstruction-planner-x56.png", icon_size = 56, small_icon = "__base__/graphics/icons/shortcut-toolbar/mip/new-deconstruction-planner-x24.png", small_icon_size = 24 } ``` -------------------------------- ### Define Custom Recipe with Probabilistic Output Source: https://lua-api.factorio.com/latest/concepts/ItemProduct.html This example demonstrates how to define a custom recipe's product with a specific probability of being produced, and a variable amount between a minimum and maximum. ```lua -- What a custom recipe would look like that had a probability of 0.5 to return a -- minimum amount of 1 and a maximum amount of 5 {{type="item", name="custom-item", probability=0.5, amount_min=1, amount_max=5}} ``` -------------------------------- ### Filter Tile Prototypes by Walking Speed Modifier Source: https://lua-api.factorio.com/latest/classes/LuaPrototypes.html Gets tile prototypes that provide a significant walking speed bonus. The example filters for tiles that increase walking speed by at least 50% (value of 1.5). ```Lua local prototypes = prototypes.get_tile_filtered{{filter="walking-speed-modifier", comparison="≥", value=1.5}} ``` -------------------------------- ### TechnologyID Example 2 Source: https://lua-api.factorio.com/latest/types/TechnologyID.html Example of a TechnologyID string. ```lua "steel-axe" ``` -------------------------------- ### Example EquipmentGridID Source: https://lua-api.factorio.com/latest/types/EquipmentGridID.html Represents the name of a small equipment grid. ```lua "small-equipment-grid" ``` -------------------------------- ### TechnologyID Example 1 Source: https://lua-api.factorio.com/latest/types/TechnologyID.html Example of a TechnologyID string. ```lua "automated-rail-transportation" ``` -------------------------------- ### Complete Fluid Prototype Example Source: https://lua-api.factorio.com/latest/prototypes/FluidPrototype.html A comprehensive example demonstrating the definition of a fluid prototype, including its name, temperature properties, color settings, icon, and ordering. ```lua { type = "fluid", name = "water", default_temperature = 15, max_temperature = 100, heat_capacity = "0.2kJ", base_color = { r = 0, g = 0.34, b = 0.6 }, flow_color = { r = 0.7, g = 0.7, b = 0.7 }, icon = "__base__/graphics/icons/fluid/water.png", icon_size = 64, order = "a[fluid]-a[water]" } ``` -------------------------------- ### SurfacePropertyID Example: magnetic-field Source: https://lua-api.factorio.com/latest/types/SurfacePropertyID.html Example of a SurfacePropertyID string. ```string "magnetic-field" ``` -------------------------------- ### Technology Upgrade Example Source: https://lua-api.factorio.com/latest/prototype-api.json Illustrates how to define a technology as an upgrade, which is relevant when a technology contains multiple levels. ```lua { upgrade = true, max_level = 5, name = "firearm-damage-upgrade", tech_cost_multiplier = 1.5, unit = { count = 50, ingredients = { {"automation-science-pack", 1}, {"chemical-science-pack", 1} }, time = 30 }, icon = "__core__/graphics/icons/firearm-damage-upgrade.png", icon_size = 32, effects = { { type = "damage", bonus = "firearm-damage", modifier = 0.2 } }, order = "r-a-a" } ``` -------------------------------- ### Example ZoomLimits Configuration Source: https://lua-api.factorio.com/latest/concepts/ZoomLimits.html This example demonstrates how to configure zoom limitations for a player. It sets the closest and furthest zoom levels, and also specifies the furthest zoom level for the game view. ```lua { closest = { zoom = 4 }, furthest = { zoom = 1 / 16 }, furthest_game_view = { distance = 200, max_distance = 400 } } ``` -------------------------------- ### SurfacePropertyID Example: solar-power Source: https://lua-api.factorio.com/latest/types/SurfacePropertyID.html Example of a SurfacePropertyID string. ```string "solar-power" ``` -------------------------------- ### AmmoCategoryID Examples Source: https://lua-api.factorio.com/latest/prototype-api.json Examples of valid AmmoCategoryID strings. ```lua "bullet" ``` ```lua "melee" ``` -------------------------------- ### Item Product Example Source: https://lua-api.factorio.com/latest/runtime-api.json Defines the products of a recipe, specifying item name, amount, and probability. ```lua -- Products of the "steel-chest" recipe (an array of Product) {{type="item", name="steel-chest", amount=1}} ``` ```lua -- What a custom recipe would look like that had a probability of 0.5 to return a -- minimum amount of 1 and a maximum amount of 5 {{type="item", name="custom-item", probability=0.5, amount_min=1, amount_max=5}} ``` -------------------------------- ### Example Products for Advanced Oil Processing Source: https://lua-api.factorio.com/latest/classes/LuaRecipe.html Illustrates the structure of products for a recipe, specifying type, name, and amount. This example corresponds to the 'advanced-oil-processing' recipe. ```lua -- The products of "advanced-oil-processing" would look like this: {{type="fluid", name="heavy-oil", amount=25}, {type="fluid", name="light-oil", amount=45}, {type="fluid", name="petroleum-gas", amount=55}} ``` -------------------------------- ### AirbornePollutantID Examples Source: https://lua-api.factorio.com/latest/prototype-api.json Examples of valid AirbornePollutantID strings. ```lua "pollution" ``` ```lua "spores" ```