<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.factorio.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jshi</id>
	<title>Official Factorio Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.factorio.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jshi"/>
	<link rel="alternate" type="text/html" href="https://wiki.factorio.com/Special:Contributions/Jshi"/>
	<updated>2026-04-26T09:07:38Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://wiki.factorio.com/index.php?title=Tutorial:Modding_tutorial/Gangsir&amp;diff=180020</id>
		<title>Tutorial:Modding tutorial/Gangsir</title>
		<link rel="alternate" type="text/html" href="https://wiki.factorio.com/index.php?title=Tutorial:Modding_tutorial/Gangsir&amp;diff=180020"/>
		<updated>2020-06-01T13:36:29Z</updated>

		<summary type="html">&lt;p&gt;Jshi: /* Multiplayer and desyncs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Languages}}&lt;br /&gt;
This is a modding tutorial for Factorio version 0.18. In this tutorial, the author will explain how Factorio works behind the scenes, how to modify Factorio, where to find documentation, and explain concepts.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Before we start the tutorial, a few things to note:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#AAFFAA!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
Code tinted green like this should be included into the mod this tutorial is going to create; If the reader follows along with it. The best way to do this is to copy and paste, to ensure faithful reproduction.&lt;br /&gt;
Whenever code is added to the mod, a Lua comment with the file name will be at the beginning of the green box. Place the code in the box into that file. Eg:&lt;br /&gt;
--control.lua&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
Code tinted purple like this should not be included into the mod, it&#039;s just for educational/example purposes, and to boost understanding.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tutorial was updated to version 0.18, so any &#039;&#039;viewers in the future should take note that some minor changes may have been made&#039;&#039;, and should look at the changelogs up to the current version.&lt;br /&gt;
&lt;br /&gt;
== Terminology used in modding ==&lt;br /&gt;
&lt;br /&gt;
Before we start the tutorial, a few terms and definitions should be laid out, to ensure the reader understands.&lt;br /&gt;
&lt;br /&gt;
; Mod : A script or series of scripts that allow modifications to the game through the API.&lt;br /&gt;
; Entity : An entity in Factorio is anything in the game that is not a concept, event, or tile. Examples of entities include the character, an assembling machine, a biter, etc. This can be &#039;machines&#039; or free-moving objects like the character.&lt;br /&gt;
; Character : The actual entity that the player manipulates the world through.&lt;br /&gt;
; Player : All the data that defines a player, such as username, online time or the current zoom level.&lt;br /&gt;
; Prototype : A prototype describes an instance of an entity or item etc, a bit like a template. It defines stats, like what an entity actually is, an item&#039;s stack size, a recipe&#039;s ingredients etc. A prototype is used to create an instance of an entity/item, and many functionally identical entities/items will use the same prototype.&lt;br /&gt;
; Surface : A surface is a bit like a dimension. It is composed of terrain, such as grass, sand, and water, and all the entities on the surface. By default, there is only one surface in Factorio, referred to internally as &amp;quot;nauvis&amp;quot;, or &amp;lt;code style=&amp;quot;background-color:#DDA0DD; color:black&amp;quot;&amp;gt;game.surfaces[1]&amp;lt;/code&amp;gt;, but mods may create additional surfaces through the API.&lt;br /&gt;
; Event : An event is a recurring...event, that is triggered internally by the game. There are several events that mods may connect functions to, such as &amp;lt;code style=&amp;quot;background-color:#DDA0DD; color:black&amp;quot;&amp;gt;on_entity_died&amp;lt;/code&amp;gt;, etc. More on this in the control scripting section.&lt;br /&gt;
&lt;br /&gt;
More terminology may be declared and defined later in this tutorial.&lt;br /&gt;
&lt;br /&gt;
== Before beginning to mod ==&lt;br /&gt;
&lt;br /&gt;
Before we can start modding Factorio, we must understand what Factorio is. You may be tempted to answer in lieu of the [[Factorio:About|about page]], but that is what a player would say. Since we are trying to become a modder, we need a more detailed explanation. Factorio is a game that is coded in the language C++, with an API provided by Wube (the developers of Factorio) to mod Factorio in the programming language Lua (version 5.2.1). This API allows adding scripts to the Factorio init process, to modify it without the source code of the base game being exposed, or modifying memory. This may be different than other games that offer modding, but this is a more professional and proper way of supporting modding.&lt;br /&gt;
&lt;br /&gt;
To aid in the use of this API, the devs have kindly provided fairly comprehensive documentation of scripting at their [https://lua-api.factorio.com/latest/ API site] and documentation all around prototypes on [[Prototype definitions|this wiki]]. Get used to using these sites, as they will become frequent visits you will make while you develop mods. The scripting API site contains information on [https://lua-api.factorio.com/latest/Classes.html Factorio&#039;s classes] and information on [https://lua-api.factorio.com/latest/events.html events] that you can hook into. [[Prototype definitions]] contains and links to information all around prototypes, listing their inheritance structure and their properties. You will need to check these sites often, so the author recommends bookmarking them. In addition to these sites, there is also many resources to be found created by the community, such as this tutorial.&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
&lt;br /&gt;
The best way to develop a mod is to develop it in a place where it can be easily tested. When the tutorial gets to making the mod, this will be explained further. Additionally, using an editor that allows ease of typing and Lua language support is recommended. Emacs, Vim, Sublime Text, VSCode, and Notepad++ are all viable candidates.&lt;br /&gt;
&lt;br /&gt;
== How Factorio loads mods ==&lt;br /&gt;
&lt;br /&gt;
=== Load order ===&lt;br /&gt;
Within stages, mods are loaded by dependency, then by alphabetical order. This is &#039;&#039;very important&#039;&#039; to understand, as it can cause you problems if you neglect it and try to add inter-mod support to your mod.&lt;br /&gt;
&lt;br /&gt;
Factorio has three kinds of dependencies. There are required dependencies, and optional dependencies. The third kind, restrictive dependencies, does not affect mod order and instead prevents the game from loading if the other mod is found. Required dependencies are loaded first, always. The game will fail to initialize if one of these is not present. Optional dependencies are loaded first if present, but do not have to be present. This is useful for enabling bonus features if mods are used together. Required dependencies should be used for mod libraries, and similar infrastructure.&lt;br /&gt;
&lt;br /&gt;
=== The settings stage ===&lt;br /&gt;
The very first mod stage that is loaded when Factorio initializes is the settings stage. This stage is used to define all mod settings that are later shown in the in-game mod settings GUI, and has no other functions or possibilities. When running through this stage, the game looks through all mods for a file called &amp;lt;code&amp;gt;settings.lua&amp;lt;/code&amp;gt;. After settings.lua has been executed for all mods, each mod&#039;s &amp;lt;code&amp;gt;settings-updates.lua&amp;lt;/code&amp;gt; is executed, and finally each mod&#039;s &amp;lt;code&amp;gt;settings-final-fixes.lua&amp;lt;/code&amp;gt; is called. These 3 different phases of the settings stage allow to change settings of other mods without needing to rely on dependencies to load last. All other files to be loaded will need to be required. All the files run here should contain nothing but setting definitions and code to produce setting definitions.&lt;br /&gt;
&lt;br /&gt;
The settings stage does not have access to prototype or runtime data because it is loaded before those stages. The settings are expected to have a certain format, and all additional code will be discarded once the stage is over.&lt;br /&gt;
&lt;br /&gt;
Mod settings are not covered in this tutorial, see [[Tutorial:Mod settings]] for further info on them.&lt;br /&gt;
&lt;br /&gt;
=== The data stage ===&lt;br /&gt;
&lt;br /&gt;
This is the most restricted part of the Factorio init, there&#039;s not much you can do here other than declare prototypes for technologies, entities, items and more. Things like manipulating files, affecting the world, etc, are blocked/unavailable. In fact, any functions or changes made will be discarded, as the lua session is terminated. You also cannot mess with the data table, it will error or be ignored. When using &amp;lt;code&amp;gt;data:extend({})&amp;lt;/code&amp;gt;, it expects a specific format, more on this later.&lt;br /&gt;
&lt;br /&gt;
When running through this stage, the game looks through all mods for a file called &amp;lt;code&amp;gt;data.lua&amp;lt;/code&amp;gt;. After data.lua has been executed for all mods, each mod&#039;s &amp;lt;code&amp;gt;data-updates.lua&amp;lt;/code&amp;gt; is executed, and finally each mod&#039;s &amp;lt;code&amp;gt;data-final-fixes.lua&amp;lt;/code&amp;gt; is called. These 3 different phases of the data stage allow to change data of other mods without needing to rely on dependencies to load last. For example, the base mod creates barrelling recipes for all (then present) fluids in data-updates.lua. This means that if you add a fluid in data.lua, the base mod&#039;s data-updates.lua will add barreling recipes for it, regardless of whether your mod depends on base. Of course this also means that if you add a fluid in data-final-fixes.lua, it is created after the barrelling code runs in data-updates.lua, so no barrelling recipe gets created, even when desired. Because of this and similar mod interactions, it is recommended to create prototypes as early as possible. So, don&#039;t use data-final-fixes.lua to exclude a fluid from barreling, instead create it in data.lua and utilize &amp;quot;auto_barrel = false&amp;quot; on the fluid.&lt;br /&gt;
&lt;br /&gt;
All other files to be loaded will need to be required. All the files run here should contain nothing but prototype definitions and code to produce prototype definitions. More on requiring files later.&lt;br /&gt;
&lt;br /&gt;
All prototypes are documented here on the wiki: [[Prototype definitions]].&lt;br /&gt;
&lt;br /&gt;
=== Migrations ===&lt;br /&gt;
&lt;br /&gt;
[https://lua-api.factorio.com/latest/Migrations.html Migrations] are scripts that are used to &amp;quot;fix&amp;quot; a save after a mod updates. Whenever prototype names change within a mod, migrations must be setup to replace all the old instances of the prototyped entity in the world. This must be done for all updated entities, or the old entities will be removed from the world, which is an unprofessional fallback that makes users dislike you. While this tutorial will not discuss migrations, there are many resources on migrations to be found around the community, and the API site.&lt;br /&gt;
&lt;br /&gt;
To avoid having to write migrations, avoid changing prototype names and technology unlocks. Prototypes names cannot be dynamically changed and technology unlocks of already researched technologies do not apply automatically, making migrations necessary. Try to avoid these changes after shipping the mod out to the public. Try to come up with a finalized version of prototype names that you can base the mod around. Of course, migrations are unnecessary if the user simply starts a new world with each mod update, but do not expect the community to do this.&lt;br /&gt;
&lt;br /&gt;
=== Runtime stage ===&lt;br /&gt;
&lt;br /&gt;
Within most mods is a file called &amp;lt;code&amp;gt;control.lua&amp;lt;/code&amp;gt;. This file contains scripting that makes the mod do things during the game, rather than just adding entities to the game. During this stage, each mod&#039;s control.lua is run, in it&#039;s own lua instance (this means no inter-communication without special setup) which it will own for the rest of the play session. During the play session, access to all tables provided by the game can be done inside of event handlers. (More on those below.) Because the control.lua is run every time a save file is created or loaded you don&#039;t need to restart the game to see changes made to the control.lua file. Simply restarting or reloading a save will re-run this stage. &#039;&#039;&#039;There are a few other caveats to this stage, reading the [https://lua-api.factorio.com/latest/Data-Lifecycle.html data life cycle] page on the API site provides the best overview.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The control stage documented is documented on [https://lua-api.factorio.com/latest lua-api.factorio.com].&lt;br /&gt;
&lt;br /&gt;
== The major components to any Factorio mod ==&lt;br /&gt;
&lt;br /&gt;
Within the average mod, there are several components that make the mod function.&lt;br /&gt;
&lt;br /&gt;
Mods that define new entities will need to declare these entities in &amp;lt;code&amp;gt;data.lua&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;data-updates.lua&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;data-final-fixes.lua&amp;lt;/code&amp;gt;, or another file &amp;lt;code&amp;gt;require&amp;lt;/code&amp;gt;d by one of these three.&lt;br /&gt;
&lt;br /&gt;
Mods with in-game effects will also need a &amp;lt;code&amp;gt;control.lua&amp;lt;/code&amp;gt; file, to add scripting.&lt;br /&gt;
&lt;br /&gt;
Mods with configurable user settings will use &amp;lt;code&amp;gt;settings.lua&amp;lt;/code&amp;gt; to describe those settings.&lt;br /&gt;
&lt;br /&gt;
Mods that define any game element with a readable name may also provide a &amp;lt;code&amp;gt;locale&amp;lt;/code&amp;gt; directory and subdirectories with names/descriptions in one or more languages.&lt;br /&gt;
&lt;br /&gt;
The mod that we&#039;ll make in this tutorial will include both data.lua prototypes and control.lua scripting, to give you a feel for both.&lt;br /&gt;
&lt;br /&gt;
== The tutorial mod ==&lt;br /&gt;
&lt;br /&gt;
And now for the moment you&#039;ve been waiting for. Let&#039;s start making your first mod. You&#039;ll need:&lt;br /&gt;
&lt;br /&gt;
* A recent install of Factorio&lt;br /&gt;
* A text editor, such as Emacs, Vim, Sublime text, etc&lt;br /&gt;
* An understanding of the tutorial above&lt;br /&gt;
* An understanding of Lua as a programming language. Enough to know the syntax and how it works. If you have prior programming experience, it should not be difficult to pick up.&lt;br /&gt;
&lt;br /&gt;
Once you have all of these things, we can begin.&lt;br /&gt;
&lt;br /&gt;
For this mod, we&#039;re going to make a set of armor that leaves behind damaging fire behind you as you walk. It will be fully resistant to fire, but weaker towards physical damage than heavy armor, making it an armor for hit and run attacks.&lt;br /&gt;
&lt;br /&gt;
=== Creation of the directory structure ===&lt;br /&gt;
&lt;br /&gt;
The game expects mod to be laid out [[Tutorial:Mod structure|in a certain way]]. To start out, create a folder in your [[Application directory|user data directory]]/mods folder. This folder must have a specific name, &amp;lt;code&amp;gt;fire-armor_0.1.0&amp;lt;/code&amp;gt;. When you&#039;re finished, the mod directory should look like this:&lt;br /&gt;
&lt;br /&gt;
* (user data directory, sometimes called .factorio)&lt;br /&gt;
** mods&lt;br /&gt;
*** fire-armor_0.1.0&lt;br /&gt;
&lt;br /&gt;
Then, inside fire-armor_0.1.0, create two files, &amp;lt;code&amp;gt;info.json&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;data.lua&amp;lt;/code&amp;gt;. The directory should now look like:&lt;br /&gt;
&lt;br /&gt;
* (user data directory, sometimes called .factorio)&lt;br /&gt;
** mods&lt;br /&gt;
*** fire-armor_0.1.0&lt;br /&gt;
**** data.lua&lt;br /&gt;
**** info.json&lt;br /&gt;
&lt;br /&gt;
=== The info.json file ===&lt;br /&gt;
&lt;br /&gt;
Then, inside [[Tutorial:Mod_structure#info.json|info.json]], copy and paste the following into it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#AAFFAA!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;name&amp;quot;: &amp;quot;fire-armor&amp;quot;,&lt;br /&gt;
  &amp;quot;version&amp;quot;: &amp;quot;0.1.0&amp;quot;,&lt;br /&gt;
  &amp;quot;title&amp;quot;: &amp;quot;Fire Armor&amp;quot;,&lt;br /&gt;
  &amp;quot;author&amp;quot;: &amp;quot;You&amp;quot;,&lt;br /&gt;
  &amp;quot;factorio_version&amp;quot;: &amp;quot;0.18&amp;quot;,&lt;br /&gt;
  &amp;quot;dependencies&amp;quot;: [&amp;quot;base &amp;gt;= 0.18&amp;quot;],&lt;br /&gt;
  &amp;quot;description&amp;quot;: &amp;quot;This mod adds in fire armor that leaves behind damaging fire as you walk around.&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To explain each field:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Item&lt;br /&gt;
! Explanation&lt;br /&gt;
|-&lt;br /&gt;
| name&lt;br /&gt;
| This is the internal name of your mod, it is used to identify your mod in code.&lt;br /&gt;
|-&lt;br /&gt;
| version&lt;br /&gt;
| This is the version of your mod. This can be anything you want, provided it&#039;s a number. Some mods start at 0.0.1 or 0.1.0, while others follow Factorio versions and start at 0.17.0 (for Factorio version 0.17.x)&lt;br /&gt;
|-&lt;br /&gt;
| title&lt;br /&gt;
| The pretty title of your mod, this will be displayed on the mods screen and when you submit it to the mod portal.&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Your name! You can change this in the example above.&lt;br /&gt;
|-&lt;br /&gt;
| factorio_version&lt;br /&gt;
| This tells the game what version the mod is for, this must match the version you&#039;re developing the mod for, 0.18 in this case.&lt;br /&gt;
|-&lt;br /&gt;
| dependencies&lt;br /&gt;
| Any dependencies of your mod.&lt;br /&gt;
|-&lt;br /&gt;
| description&lt;br /&gt;
| A &#039;&#039;short&#039;&#039; description of your mod.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
And that&#039;s all for info.json! Next, in the data.lua file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#AAFFAA!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
--data.lua&lt;br /&gt;
&lt;br /&gt;
require(&amp;quot;item&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It&#039;s a pretty simple file, all we&#039;re doing here is just telling the game to execute the file called item.lua, which we&#039;re about to create. Create a file in fire-armor_0.1.0 called &amp;lt;code&amp;gt;item.lua&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Notice how our earlier require used the file name in it?&lt;br /&gt;
&lt;br /&gt;
=== Prototype creation ===&lt;br /&gt;
&lt;br /&gt;
Now, there are two ways to create prototypes in Factorio. There&#039;s the short way, and the long way. The long way requires to create a complete prototype definition based on [[prototype definitions|the documentation]], and the short way just uses a lua function to copy and modify an already existing definition. For the sake of this tutorial, we&#039;ll do it the short way.&lt;br /&gt;
&lt;br /&gt;
In item.lua, copy and paste the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#AAFFAA!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
--item.lua&lt;br /&gt;
&lt;br /&gt;
local fireArmor = table.deepcopy(data.raw[&amp;quot;armor&amp;quot;][&amp;quot;heavy-armor&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
fireArmor.name = &amp;quot;fire-armor&amp;quot;&lt;br /&gt;
fireArmor.icons= {&lt;br /&gt;
  {&lt;br /&gt;
    icon=fireArmor.icon,&lt;br /&gt;
    tint={r=1,g=0,b=0,a=0.3}&lt;br /&gt;
  },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
fireArmor.resistances = {&lt;br /&gt;
  {&lt;br /&gt;
    type = &amp;quot;physical&amp;quot;,&lt;br /&gt;
    decrease = 6,&lt;br /&gt;
    percent = 10&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    type = &amp;quot;explosion&amp;quot;,&lt;br /&gt;
    decrease = 10,&lt;br /&gt;
    percent = 30&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    type = &amp;quot;acid&amp;quot;,&lt;br /&gt;
    decrease = 5,&lt;br /&gt;
    percent = 30&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    type = &amp;quot;fire&amp;quot;,&lt;br /&gt;
    decrease = 0,&lt;br /&gt;
    percent = 100&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local recipe = table.deepcopy(data.raw[&amp;quot;recipe&amp;quot;][&amp;quot;heavy-armor&amp;quot;])&lt;br /&gt;
recipe.enabled = true&lt;br /&gt;
recipe.name = &amp;quot;fire-armor&amp;quot;&lt;br /&gt;
recipe.ingredients = {{&amp;quot;copper-plate&amp;quot;,200},{&amp;quot;steel-plate&amp;quot;,50}}&lt;br /&gt;
recipe.result = &amp;quot;fire-armor&amp;quot;&lt;br /&gt;
&lt;br /&gt;
data:extend{fireArmor,recipe}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What we&#039;ve just done here is we&#039;ve copied the definition of heavy armor, then changed it&#039;s properties, and injected it into the Factorio init with data:extend. The first line of code is probably the most interesting. &amp;lt;code&amp;gt;table.deepcopy&amp;lt;/code&amp;gt; copies a table fully into another table. We do this from data.raw. The &amp;lt;code&amp;gt;data&amp;lt;/code&amp;gt; part is a table, which will be used by game to setup the Factorio universe. In fact, it contains the function &amp;lt;code&amp;gt;extend(self, prototypes)&amp;lt;/code&amp;gt; and a table called &amp;lt;code&amp;gt;raw&amp;lt;/code&amp;gt;. The former is customary way to add new stuff to the latter. It is actually data.raw that holds the prototypes for the game. (You can view the implementation in the file [https://github.com/wube/factorio-data/blob/master/core/lualib/dataloader.lua /factorio/data/core/lualib/dataloader.lua]). It is important to note that data.raw only exists during the data loading stage of the game. During the control stage, when the game is running and being played, you cannot read this data; instead you read processed values through the API from the various types like LuaEntityPrototype.&lt;br /&gt;
&lt;br /&gt;
In addition to defining the item prototype, we also define a recipe for it. This is necessary if you want to be able to craft the thing. We also set it to enabled so it doesn&#039;t need a technology to unlock.&lt;br /&gt;
&lt;br /&gt;
=== More on data.raw ===&lt;br /&gt;
&lt;br /&gt;
When Factorio initializes, all prototypes are put into a table called data.raw. This table holds all prototype types, and within those types, individual prototypes indentified by name: &amp;lt;code&amp;gt;local prototype = data.raw[&amp;quot;prototype-type&amp;quot;][&amp;quot;internal-name&amp;quot;]&amp;lt;/code&amp;gt;. You saw earlier how we deepcopied from the definition of heavy armor, and modified some fields. In fact, let&#039;s go over each part of the deepcopy line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
local fireArmor = table.deepcopy(data.raw[&amp;quot;armor&amp;quot;][&amp;quot;heavy-armor&amp;quot;])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We assign a variable called fireArmor that holds our copy of the heavy armor definition. Notice how in data.raw, there is a type table that holds all armors, and the specific armor we&#039;re looking for is called heavy-armor. We can find [[heavy armor]]&#039;s prototype type and internal name in the infobox of its page on this wiki and just copy it from there.&amp;lt;br&amp;gt;&lt;br /&gt;
Alternatively, we can find the items prototype type and internal name by opening the game, inserting the item into our inventory and then pressing {{Keybinding|shift|ctrl|F}} while hovering over the item. This will open the prototype explorer GUI, which has rows showing the name and type of the item.&lt;br /&gt;
&lt;br /&gt;
As another example, the [[player|character]]&#039;s prototype would be, according to the infobox on the page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
data.raw[&amp;quot;character&amp;quot;][&amp;quot;character&amp;quot;]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the character is &#039;&#039;the&#039;&#039; character, his type matches his name. You could define a new type of character with a mod. You can see all the available prototype fields of the charater in the documenation: [[Prototype/Character]].&lt;br /&gt;
&lt;br /&gt;
You may be thinking at this point, &amp;quot;Can I modify Factorio&#039;s existing prototypes without making new ones?&amp;quot; Well, the answer is yes! You would simply access the data.raw table during init, in data-final-fixes.lua if you want to run after all other mods, and change a property. For example, make the iron chest instead have 1000 health:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
data.raw[&amp;quot;container&amp;quot;][&amp;quot;iron-chest&amp;quot;].max_health = 1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The reason why this code is in data-final-fixes.lua is because that is the last file run, after all mod files have been run. This prevents (to a degree) your changes from being messed with by other mods. Of course, it is still possible to have incompatibilities. You should note any that you know of in your mod&#039;s description. Again, the [https://lua-api.factorio.com/latest/Data-Lifecycle.html dev&#039;s documentation] on this should be looked at.&lt;br /&gt;
&lt;br /&gt;
This can also be applied to other mods, not just Factorio&#039;s base. You could mod a mod, as long as you add the mod (that you modified with your mod) to your dependencies so it gets loaded first.&lt;br /&gt;
&lt;br /&gt;
=== The control scripting ===&lt;br /&gt;
&lt;br /&gt;
And now, to finalize the mod, we have to make it be more than just simple armor. Let&#039;s think about what we want the armor to do. We want the armor to create fire on the ground as we walk with the armor on. The event we&#039;re going to use is called [https://lua-api.factorio.com/latest/events.html#on_player_changed_position on_player_changed_position], since we want the fire to be created when the player moves.&lt;br /&gt;
&lt;br /&gt;
In our mod folder, create a file called &amp;lt;code&amp;gt;control.lua&amp;lt;/code&amp;gt;. The game will automatically execute this file, so requiring it is not necessary.&lt;br /&gt;
&lt;br /&gt;
Inside control.lua, copy and paste the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#AAFFAA!important; color:black;&amp;quot;&amp;gt;&lt;br /&gt;
--control.lua&lt;br /&gt;
&lt;br /&gt;
script.on_event(defines.events.on_player_changed_position,&lt;br /&gt;
  function(event)&lt;br /&gt;
    local player = game.get_player(event.player_index) -- get the player that moved            &lt;br /&gt;
    -- if they&#039;re wearing our armor&lt;br /&gt;
    if player.character and player.get_inventory(defines.inventory.character_armor).get_item_count(&amp;quot;fire-armor&amp;quot;) &amp;gt;= 1 then&lt;br /&gt;
       -- create the fire where they&#039;re standing&lt;br /&gt;
       player.surface.create_entity{name=&amp;quot;fire-flame&amp;quot;, position=player.position, force=&amp;quot;neutral&amp;quot;} &lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I&#039;ve used lua comments in the code above to explain each step. It&#039;s fairly easy to understand, and it shows how you would get the current armor that the player character is wearing, with defines.inventory.character_armor, which is an inventory constant. You can read the list of defines [https://lua-api.factorio.com/latest/defines.html#defines.inventory here].&lt;br /&gt;
&lt;br /&gt;
=== Locale ===&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already tried loading up Factorio and trying the mod so far (which you can at this point without it crashing), you may have noticed that the item name of the armor says &amp;quot;Unknown key&amp;quot;. This means that Factorio has the internal name, but it doesn&#039;t know what it should look like to the user. So, we need to create locale for our mod.&lt;br /&gt;
&lt;br /&gt;
In the mod folder, create a folder called &amp;lt;code&amp;gt;locale&amp;lt;/code&amp;gt;, then create another folder inside that called &amp;lt;code&amp;gt;en&amp;lt;/code&amp;gt;, then a file called &amp;lt;code&amp;gt;config.cfg&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you know another language, you can also translate your mod by making other language code files inside locale, such as de for German.&lt;br /&gt;
&lt;br /&gt;
Inside config.cfg, paste the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#AAFFAA!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[item-name]&lt;br /&gt;
fire-armor=Fire armor&lt;br /&gt;
&lt;br /&gt;
[item-description]&lt;br /&gt;
fire-armor=An armor that seems to catch the ground itself on fire when you take a step. It&#039;s warm to the touch.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how this is not a lua file. Locale is handled with C config files, so the format is different.&lt;br /&gt;
&lt;br /&gt;
== The finished tutorial mod ==&lt;br /&gt;
&lt;br /&gt;
Well, the mod is finished. Since this mod is only a tutorial, there isn&#039;t much balance to it. Additionally, don&#039;t try submitting it to the mod portal as your own, since it&#039;s from the Wiki.&lt;br /&gt;
&lt;br /&gt;
However, you&#039;re free to take this mod and modify it for your own use, changing recipes, adding technologies, whatever.&lt;br /&gt;
&lt;br /&gt;
== Resolving common errors in modding ==&lt;br /&gt;
&lt;br /&gt;
As you continue to write mods from scratch instead of from a tutorial, you may encounter the infamous error. There are several types of errors that you can encounter in modding Factorio, and knowing how to deal with these errors will allow you to continue working.&lt;br /&gt;
&lt;br /&gt;
=== Syntax errors ===&lt;br /&gt;
&lt;br /&gt;
The lua programming language expects things to be laid out a certain way. If you miss a bracket, = sign, or dot, you will encounter a syntax error. As an example, see the error below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
Failed to load mods: __fire-armor__/data.lua:1:__fire-armor__/prototypes/item.lua:36: syntax error near &#039;true&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As of version 0.15, you&#039;ll see an error like the one above whenever you make a syntax error within the prototype definitions. The game will offer to restart, disable the troubling mod, disable all mods, or exit. Let&#039;s dissect the error, shall we?&lt;br /&gt;
&lt;br /&gt;
Right away, we see the reason why Factorio didn&#039;t start normally. &amp;quot;Failed to load mods:&amp;quot;. So, we know that it&#039;s a mod that messed up, and by extension, we know it&#039;s our mod. Whenever the Lua engine of Factorio has a syntax error, it will print a mini stack-trace that follows through all requires, listing the call order. First, we see that the problem was indirectly caused by line 1 of data.lua. There&#039;s no problem there, so it must be the next entry, line 36 of prototypes/item.lua. After stating where it is line-wise, it will attempt to give you an estimate of where in the line the problem is. Don&#039;t trust this estimate, only roughly trust the line number, plus or minus a few lines.&lt;br /&gt;
&lt;br /&gt;
Going to line 36 of item.lua, we find:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
recipe.enabled true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hmm, that doesn&#039;t look right. Can you see what&#039;s missing? We left off an = between enabled and true. Thus, syntax error. Fixing these can be difficult for new programmers, who don&#039;t know what to look for.&lt;br /&gt;
&lt;br /&gt;
=== Illogical actions, indexing nil ===&lt;br /&gt;
&lt;br /&gt;
In lua, &amp;quot;nothing&amp;quot; is defined as the keyword nil. This is similar to null in other programming languages. Whenever the programmer tries to access something in a table that is nil, they will get an error like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
Error while running event fire-armor::on_player_changed_position (ID 82)&lt;br /&gt;
__fire-armor__/control.lua:3: attempt to index field &#039;?&#039; (a nil value)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;attempt to index field ...&amp;quot; error is often caused by the modder making an assumption that didn&#039;t work out. These types of errors will always be identifiable by their signature line, &amp;quot;attempt to index field&amp;quot;. If we look at line 3 of control.lua (where the error is), we see:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
game.print(game.players[23])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What assumption has the modder made here? Well, there&#039;s actually two problems with this line. The first thing is that the modder has assumed that &amp;lt;code&amp;gt;game.players[23]&amp;lt;/code&amp;gt; is a valid player, which isn&#039;t the case; this is why we get the &amp;quot;index field &#039;?&#039;&amp;quot; bit. The game doesn&#039;t know what the field is that we tried to index, because it hasn&#039;t been created yet. These errors are difficult to debug unless you know the ins and outs of the modding API well.&lt;br /&gt;
&lt;br /&gt;
The second issue is a lot more subtle, and won&#039;t work. The modder is attempting to print a userdata table. [https://lua-api.factorio.com/latest/LuaPlayer A player] is a table of several values. Trying to print it simply print &amp;quot;LuaPlayer&amp;quot; instead of providing useful data.&lt;br /&gt;
&lt;br /&gt;
=== Error while running event ===&lt;br /&gt;
&lt;br /&gt;
Another common type of error in Factorio is the &amp;quot;Error while running event&amp;quot; error. This type of error only happens in control.lua scripting, and it happens when something goes wrong in an event function, such as a syntax error. &#039;&#039;&#039;Note that syntax errors in control.lua do not stop the game from starting, but may trigger after a save is loaded&#039;&#039;&#039;. There are a great deal of errors under this broad category, here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
Error while running event fire-armor::on_player_changed_position (ID 82)&lt;br /&gt;
Unknown entity name: fire-flam&lt;br /&gt;
stack traceback:&lt;br /&gt;
__fire-armor__/control.lua:7: in function &amp;lt;__fire-armor__/control.lua:2&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you saw with the prototypes syntax error, Factorio gives a small traceback and the error name itself. In this case, we&#039;ve attempted to spawn an entity called &amp;quot;fire-flam&amp;quot; on line 7 of control.lua, inside of an on_player_changed_position event hook. Fire-flam isn&#039;t a real entity type, so we crashed.&lt;br /&gt;
&lt;br /&gt;
These types of errors can range from being a simple fix (like the one above, add the missing e), or can be very difficult.&lt;br /&gt;
&lt;br /&gt;
=== Internal errors ===&lt;br /&gt;
&lt;br /&gt;
The most rare form of error and the worst form is the internal error. This is an error with the C++ code of the game, and there&#039;s nothing you can do but report it to the devs. Mods occasionally cause these, and almost all of them are considered bugs, as mods &#039;&#039;should not&#039;&#039; be able to cause these, if that makes sense. They often get thrown into the logs.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
696.148 Error FlowStatistics.cpp:236: FlowStatistics attempted to save value larger than uint16 as uint16. Exiting to prevent save corruption.&lt;br /&gt;
Logger::writeStacktrace skipped.&lt;br /&gt;
696.148 Error CrashHandler.cpp:190: Map tick at moment of crash: 432029&lt;br /&gt;
696.148 Error Util.cpp:97: Unexpected error occurred. If you&#039;re running the latest version of the game you can help us solve the problem by posting the contents of the log file on the Factorio forums.&lt;br /&gt;
Please also include the save file(s), any mods you may be using, and any steps you know of to reproduce the crash.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Multiplayer and desyncs ==&lt;br /&gt;
&lt;br /&gt;
The reader may be wondering at this point how Factorio handles multiplayer with mods. It&#039;s fairly simple, but is still worth considering.&lt;br /&gt;
&lt;br /&gt;
Factorio is [https://en.wikipedia.org/wiki/Deterministic_algorithm deterministic], which means that when you provide a constant input, you get a constant output, with no variance. Every client and the server all reach the same points at the same time in simulation, so they all agree on what happened. When this differs, the players experience a &#039;&#039;desync&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
; Desync : Misalignment with server and clients. Client 1 expected A, but got B. All other clients got A. Thus, Client 1 will desync. Desync can also happen when all clients have information (for example a variable) but a client that recently joined the game doesn&#039;t. That client will be desynced.&lt;br /&gt;
: &#039;&#039;See also: [[Desynchronization]]&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Desyncs happen a lot to new devs of Factorio mods, because they are unaware that a particular piece of code they used causes desyncs. As a general rule, there are a few things that should never be done.&lt;br /&gt;
&lt;br /&gt;
=== Use local variables that are not final outside of event hooks ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
local globalLocal = 1&lt;br /&gt;
script.on_event(defines.events.on_player_built_item, function()&lt;br /&gt;
    globalLocal = math.random()&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the modder places a local variable outside of an event hook that gets changed during runtime, desyncs will happen when that variable is utilised to modify the game state (i.e. manipulate an entity, print text to players). If making a &amp;quot;global&amp;quot; variable is necessary, place the variable in the [https://lua-api.factorio.com/latest/Global.html global] table instead. The game syncs this table between all clients, so they can all be aware of and reach the same conclusion as each other.&lt;br /&gt;
&lt;br /&gt;
=== Selective requiring ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
if setting1 then&lt;br /&gt;
   require(&amp;quot;settingOne.lua&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Selective requiring, aka requiring different lua files based on settings can cause connection rejections as the checksum of the mods will not match, as they load different data. All clients&#039; mods must require the same series of files.&lt;br /&gt;
&lt;br /&gt;
=== Conditional event subscribing ===&lt;br /&gt;
&lt;br /&gt;
Mods in factorio may subscribe to events in order to be notified when they happen. This allows mods to react to events when they occur. Typically, event subscription is done at the top level of a lua file. &lt;br /&gt;
&lt;br /&gt;
Doing event subscription inside of a conditional, function, or other event is dangerous, as doing it incorrectly will lead to desyncs. Basically, since both the server and client need to reach the same conclusion after running code, conditional subscription can lead to certain clients or the server being subscribed to an event when the others are not, causing desyncs. &lt;br /&gt;
&lt;br /&gt;
=== Improper use of on_load ===&lt;br /&gt;
&lt;br /&gt;
Another way to cause desyncs is to make improper actions inside of an on_load call, which some players new to modding might try to do. According to the [https://lua-api.factorio.com/latest/LuaBootstrap.html#LuaBootstrap.on_load documentation], the on_load functionality is meant for 3 purposes &#039;&#039;&#039;only&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Re-register conditional event handlers&lt;br /&gt;
* Re-setup meta tables&lt;br /&gt;
* Create local references to tables stored in the global table&lt;br /&gt;
&lt;br /&gt;
Doing anything else will cause desyncs. The game will catch most attempts, crashing instead and terminating the mod.&lt;br /&gt;
&lt;br /&gt;
=== Comparison by reference ===&lt;br /&gt;
&lt;br /&gt;
Be cautious of comparing tables by reference, for example when using the Singleton programming pattern.&lt;br /&gt;
&lt;br /&gt;
In multiplayer syncing, tables deserialized from the server state will be new objects, not equal by reference to any table initialized by client code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
if a == b then&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:#DDA0DD!important; color:black&amp;quot;&amp;gt;&lt;br /&gt;
if a ~= b then&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt; are tables in the above conditionals, there will for example be different results between server and client if &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; is created locally and &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt; is downloaded from the server.&lt;br /&gt;
&lt;br /&gt;
== Extended learning ==&lt;br /&gt;
&lt;br /&gt;
One of the best ways to learn how to mod beyond this is to look at other mods. As all mods can be opened and looked at, looking at the mods of experienced modders can help significantly when making your own mod.&lt;br /&gt;
&lt;br /&gt;
=== Keeping your mod working ===&lt;br /&gt;
&lt;br /&gt;
As Factorio evolves, things will change. Previously, you probably ignored the modding part of the changelog, you now need to read it and see if any changes affect your mod(s). If so, you&#039;ll need to fix them. If there&#039;s something wrong with your mod, the game will fail to init and explain why.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Modding]]&lt;br /&gt;
* [[Modding FAQ]]&lt;/div&gt;</summary>
		<author><name>Jshi</name></author>
	</entry>
	<entry>
		<id>https://wiki.factorio.com/index.php?title=Circuit_network&amp;diff=179531</id>
		<title>Circuit network</title>
		<link rel="alternate" type="text/html" href="https://wiki.factorio.com/index.php?title=Circuit_network&amp;diff=179531"/>
		<updated>2020-05-19T11:15:31Z</updated>

		<summary type="html">&lt;p&gt;Jshi: /* Devices */ document filter inserter signal settings&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Languages}}&lt;br /&gt;
&#039;&#039;&#039;Circuit networks&#039;&#039;&#039; are built using [[Red wire|red]] or [[green wire]], and enable the control of receivers, based upon information broadcast onto the network by connected senders.  Most senders are storage devices, and broadcast their information onto a specific channel, based on the item or liquid the storage device contains.  Each circuit network contains a channel for every kind of item, as well as 48 extra [[#Virtual signals|virtual signals]] which act as user-definable channels. &#039;&amp;lt;span style=&amp;quot;color:#FF6666&amp;quot;&amp;gt;Everything&amp;lt;/span&amp;gt;&#039;, &#039;&amp;lt;span style=&amp;quot;color:#99FF99&amp;quot;&amp;gt;Anything&amp;lt;/span&amp;gt;&#039; and &#039;&amp;lt;span style=&amp;quot;color:#FFFF99&amp;quot;&amp;gt;Each&amp;lt;/span&amp;gt;&#039; are also available wildcards.&lt;br /&gt;
&lt;br /&gt;
[[File:shared_circuit_network.png|thumb|600px|right|Two circuit networks shared over one electric pole.]] &lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
=== Send information ===&lt;br /&gt;
Senders broadcast the amount of items or fluids they contain or other data definable by the player. Each amount is broadcast as a numeric value on a &#039;channel&#039; corresponding to the item.  For example, a Storage Tank containing 1000 Crude Oil will broadcast 1000 on the Crude Oil channel.&lt;br /&gt;
&lt;br /&gt;
The channels are separated from each other, so each network can simultaneously carry a number for each item and fluid in the game, and for each of the extra user-defined channels (digits 0-9, letters A-Z, and 9 different colors). All unused channels have the value zero.&lt;br /&gt;
&lt;br /&gt;
Multiple broadcasts of the same item or fluid are additive: If there are two connected Storage Tanks with 1000 Crude Oil each, the value of the Crude Oil channel within the network will be 2000.&lt;br /&gt;
&lt;br /&gt;
All wires of the same color which are connected together by junctions form a network, i.e. they will pass their signals to each other.  For example, if two red wires are connected to the same combinator input, each wire receives the content from the other.  This can result in feedback if care is not taken; see Feedback (under [[#Combinators|arithmetic combinator]], below) for discussion.&lt;br /&gt;
&lt;br /&gt;
Numbers are in the signed 32 bit integer range, i.e. from -2147483648 to 2147483647 inclusive, and are encoded in [https://en.wikipedia.org/wiki/Two%27s_complement two&#039;s complement representation]. The numbers wrap around on overflow, so e.g. 2147483647 + 10 becomes -2147483639. When entering a number in a combinator it can appear to exceed the 32 bit limit until the GUI is closed, at which point the number will overflow/underflow. [https://forums.factorio.com/58419]&lt;br /&gt;
&lt;br /&gt;
=== Control devices ===&lt;br /&gt;
Receivers can use broadcast information, in most cases to enable/disable the device. They can either compare results between different channels, or compare a channel to a specific value.&lt;br /&gt;
&lt;br /&gt;
Receiving devices sum all signals from each wire connected to them, even red and green wires. For example, if an inserter is connected to a red wire carrying a signal for 20 copper plates and a green wire with 10 copper plates, the input signal set for that receiver will be 30 copper plates. &lt;br /&gt;
&lt;br /&gt;
Multiple wires of the same color will share &amp;amp; sum their signals. For example, 3 chests A, B and C connected in a row (A -&amp;gt; B -&amp;gt; C) with green wire will output the sum of their contents along any green wire connected to any of the chests. However, if a red wire connects chest A to an inserter, that inserter will only be given the contents of A as its input signal.&lt;br /&gt;
&lt;br /&gt;
== Devices ==&lt;br /&gt;
&lt;br /&gt;
Each device that is able to be connected to a circuit network has a [[File:Circuit network panel.png]] icon located in the top right corner of its info pane. Clicking this icon will display the available circuit network options for that device (note: a red or green wire must be connected, otherwise the message &amp;quot;not connected&amp;quot; will display instead). Clicking the [[File:Logistic network panel.png]] icon next to it, the device can be connected to a logistic network if in range of one, which also allows conditions to be set.&lt;br /&gt;
&lt;br /&gt;
Conditions can be set for both circuit (signals of red and green wires are summed) and logistic network, which will together act as a logical AND.&lt;br /&gt;
&lt;br /&gt;
The following devices can be connected to a circuit network:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable mw-collapsible&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Icon !! Name !! Possible output signals !! Possible control options&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Transport belt||Transport belts}} || [[Transport belts]] || Transport belts can send their content to the circuit network.&lt;br /&gt;
*&#039;&#039;Pulse mode&#039;&#039;: The signal is sent for only 1 tick when the item enters the belt.&lt;br /&gt;
*&#039;&#039;Hold mode&#039;&#039;: The signal is sent continuously as long as the items are on the belt.&lt;br /&gt;
|| Transport belts can be enabled on a condition.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Inserter||Inserters}} || [[Inserters]] || All inserters can send their held items to the circuit network.&lt;br /&gt;
*&#039;&#039;Pulse mode&#039;&#039;: The signal is sent for only 1 tick when the item is picked up.&lt;br /&gt;
*&#039;&#039;Hold mode&#039;&#039;: The signal is sent continuously as long as the inserter is holding the item. &lt;br /&gt;
|| All inserters can be enabled on a condition. The inserter stack size can also be overridden from a control signal (configurable).&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Filter inserter}} || [[Filter inserter]] || Same as above. || The filter inserters can additionally set their filters from the circuit network: up to 5 items whose corresponding signal has a positive value are whitelisted.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Wooden chest||Chests}} || [[Chests]] || All chests can send their contents to the circuit network. Logistic chests additionally send their contents to the [[logistic network]]. ||&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Requester chest}} || [[Requester chest]] || Same as above. || Its requested items can be set by the circuit network.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Storage tank}} || [[Storage tank]] || The storage tank can send its fluid content to the circuit network. ||&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Gate}} || [[Gate]] || Gates can send a signal to the circuit network. || Gates can be opened on a condition.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Rail signal}} || [[Rail signal]] || Rail signals can send their state to the circuit network. || Rail signals can be set to red on a condition.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Rail chain signal}} || [[Rail chain signal]] || Rail chain signals can send their state to the circuit network. || &lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Train stop}} || [[Train stop]] || Train stations can send the contents of a stopped train to the circuit network as well as read a unique train identifier code. || Train stations can send the contents of the circuit network to the train to use it for wait conditions, as well as enable/disable the stop itself.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Accumulator}} || [[Accumulator]] || It can send its charge level in percent to the circuit network. ||&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Roboport}} || [[Roboport]] || It can send its logistic network contents and/or its robot statistics to the circuit network. The signals used for robot statistics are configurable. ||&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Burner mining drill}} || [[Mining drill]]s || All mining drills can send the expected resources, either from the drill itself or from the whole ore patch the drill is on. || Mining drills can be enabled on a condition.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Pumpjack}} || [[Pumpjack]] || It can output the current oil mining rate. || It can be enabled on a condition.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Power switch}} || [[Power switch]] || || Power switches can connect power networks on a condition.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Programmable speaker}} || [[Programmable speaker]] || || Shows alerts and plays sounds based on circuit network signals. It can be used to make simple tunes.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Lamp}} || [[Lamp]] || || The lamp can be enabled on a condition. If it receives color signals, it can set the given color.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Offshore pump}} || [[Offshore pump]] || || The offshore pump can be enabled on a condition.&lt;br /&gt;
|-&lt;br /&gt;
| {{Icon|Pump}} || [[Pump]] || || The pump can be enabled on a condition.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Physical network structure ==&lt;br /&gt;
A circuit network consists only of those devices connected together with the same color wire. Wire can be strung directly from device to device, or across any intervening power poles. Wire length is limited by its previous connection.&lt;br /&gt;
&lt;br /&gt;
Note that each connected set of wires forms a separate network.  For example, it&#039;s entirely possible to have four red-wire networks and three green-wire networks. If red and green wires happen to touch the same power pole or device, the red and green networks will remain separate and will not link up. However, two red cables or two green cables will link if they touch. Use different colored cables to separate networks in close proximity.&lt;br /&gt;
&lt;br /&gt;
* To connect wires or cables to a power pole, simply click on one entity, then on the base of the power pole.&lt;br /&gt;
* To erase a wire or cable connection, place the same color wire over an existing connection. You don&#039;t get the wire/cable back.&lt;br /&gt;
* To remove &#039;&#039;&#039;all&#039;&#039;&#039; connections from a power pole, shift-click on the pole.  The first shift-click will remove all electrical connections, and the second will remove all red and green wires. You don&#039;t get the wires back.&lt;br /&gt;
* When connecting to a [[arithmetic combinator]] or [[decider combinator]], take care to connect the wire to the correct input or output side. Use &amp;quot;Show details&amp;quot; mode to see the orientation of the combinator.&lt;br /&gt;
* Hovering the mouse cursor over an item will highlight all wires which connect to the item.&lt;br /&gt;
* Hovering the mouse cursor over a power pole which is part of a network will display the signals on its network. Some items like combinators will also display their input and output signals when hovered over.&lt;br /&gt;
&lt;br /&gt;
== Combinators ==&lt;br /&gt;
Combinators can function as both receiving and sending devices and allow more advanced functions to be used on a circuit network.&lt;br /&gt;
&lt;br /&gt;
*The [[constant combinator]] broadcasts up to 15 values on any of the channels for whatever networks it is connected to.  (You cannot currently specify whether a value should be on the red or green channel; if you need different values, use two combinators, one for each color wire.)  You can use any item channel or any of the [[#Virtual signals|virtual signal]] channels.&lt;br /&gt;
**Note that using two of the 15 slots to broadcast values on the &#039;&#039;&#039;same&#039;&#039;&#039; channel is the same as broadcasting the sum of the two values from one slot.&lt;br /&gt;
*The [[arithmetic combinator]] performs arithmetic operations on input values and broadcasts the result to the specified output channel.  The input and output channels can be any item channel or any of the virtual signal channels.&lt;br /&gt;
** Connecting: The arithmetic combinator connects to a red or green network on its &#039;&#039;&#039;input&#039;&#039;&#039; side (the terminals are set into the main body and look like spark plugs) and performs an arithmetic calculation which is broadcast into the specified channel on its &#039;&#039;&#039;output&#039;&#039;&#039; side (the output wires appear to stretch out a bit from the body of the device). &lt;br /&gt;
** Feedback: Note that the input network and the output network &#039;&#039;&#039;are not the same network&#039;&#039;&#039;.  Connecting the output network back to the input network will result in a feedback loop.  For example, adding 1 to the value for copper plates and broadcasting it as copper plates is an action that results in an infinite loop if output is connected back to input.  The value for copper plates will rapidly (but not instantly) shoot upward. (The rate at which it climbs is determined by the current tick rate.) This technique can be combined with decider combinator logic to make electronic clocks, gates, and other systems; see [[Combinator Tutorial]] for advanced techniques.&lt;br /&gt;
** Each:  This combinator can use the &#039;Each&#039; signal for both input and output, in which case &#039;&#039;&#039;all&#039;&#039;&#039; non-zero input channels will have the combinator&#039;s operation performed and broadcast on the output side.  Having Each signals for input and output and using a non-changing operation (like adding zero) is equivalent to having a &#039;one-way&#039; wire; all the information from the input network is copied to the output network, but the reverse is not true.&lt;br /&gt;
**Multi-network: The arithmetic combinator can be joined to both red and green networks on the input side and will sum their inputs.&lt;br /&gt;
*The [[decider combinator]] functions much like an arithmetic combinator, but is designed to compare values. Essentially, it is a conditional. In terms of connecting, feedback, and the Each signal it functions as specified above.  In addition, it can handle the Everything and Anything signals, and performs more complex functions than summing when attached to multiple networks.  See the [[decider combinator]] page for more details on how to use this.&lt;br /&gt;
&lt;br /&gt;
== Virtual signals == &lt;br /&gt;
[[File:Virtual Signals dialog box.png|thumb|Virtual Signals available for use in the circuit network]]&lt;br /&gt;
Virtual signals are special non-item signals. Other than the three logic signals, virtual signals do not behave differently from item signals.&lt;br /&gt;
&lt;br /&gt;
48 virtual signals can be sent over a network. They include the digits zero through nine, the letters A through Z, a check-mark, dot and info icon, and the colors red, green, blue, yellow, magenta, cyan, white, gray and black.&lt;br /&gt;
&lt;br /&gt;
=== Logic signals ===&lt;br /&gt;
[[File:logic_signals.png|300px|thumb|The icons of the three logic signals]]&lt;br /&gt;
Three of the virtual signals cannot be sent over a network but apply special logic to multiple signals.&lt;br /&gt;
&lt;br /&gt;
==== Everything ====&lt;br /&gt;
&#039;&#039;&amp;lt;span style=&amp;quot;color:#FF6666&amp;quot;&amp;gt;Everything&amp;lt;/span&amp;gt;&#039;&#039; can be used on the left side in conditionals. The condition will be true when the condition is true for each input signal. The condition is also true if there are no signals. This means that the &#039;&#039;everything&#039;&#039; signal behaves as [[:Wikipedia:universal quantification|universal quantification]].&lt;br /&gt;
&lt;br /&gt;
The output of a [[decider combinator]] may also use &#039;&#039;everything&#039;&#039;, unless the input is set to &#039;&#039;each&#039;&#039;. When used, the combinator will output signal on every channel with non-zero input as long as the condition is true; the value will either be the input value or 1, depending on the corresponding setting.&lt;br /&gt;
&lt;br /&gt;
==== Anything ====&lt;br /&gt;
&#039;&#039;&amp;lt;span style=&amp;quot;color:#99FF99&amp;quot;&amp;gt;Anything&amp;lt;/span&amp;gt;&#039;&#039; can be used on the left side of conditions. It will be false when there are no inputs. The condition will be true when the condition is true for at least one signal. This means the &#039;&#039;anything&#039;&#039; signal behaves as [[:Wikipedia:existential quantification|existential quantification]].&lt;br /&gt;
&lt;br /&gt;
==== Each ====&lt;br /&gt;
&#039;&#039;&amp;lt;span style=&amp;quot;color:#FFFF99&amp;quot;&amp;gt;Each&amp;lt;/span&amp;gt;&#039;&#039; can only be used in left input side and output of [[decider combinator|decider]] and [[arithmetic combinator|arithmetic]] combinators. The signal can only be used as an output when also used as an input. When used in both the input and output, it makes a combinator perform its action on each input signal individually. The combinator will output the sum of each of the actions if only used in the input.&lt;br /&gt;
&lt;br /&gt;
== Tutorials ==&lt;br /&gt;
*&#039;&#039;&#039;[[Circuit-network Cookbook]]&#039;&#039;&#039; - &#039;&#039;Example-heavy tutorials; for beginners who want to get to know and use the benefits of the circuit network.&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;[[Combinator Tutorial]]&#039;&#039;&#039; - &#039;&#039;Mainly textual and detailed tutorials.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Logistic network ==&lt;br /&gt;
The logistic network used by [[logistic robot]]s is essentially a third network (a wireless one), along with the green and red wired networks. The logistic network is based on proximity to a central [[roboport]].&lt;br /&gt;
&lt;br /&gt;
Some devices can also be connected to the logistic network. If a device has conditions set for circuit and for logistic network, it will become activated if both conditions are true.&lt;br /&gt;
&lt;br /&gt;
See the [[logistic network]] and [[roboport]] articles for more information.&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
&lt;br /&gt;
{{history|0.15.0|&lt;br /&gt;
* Significantly improved circuit network performance. Up to 25 times less CPU usage and 10% less memory usage.&lt;br /&gt;
* Added the Programmable Speaker: it shows alerts and plays sounds based on circuit network signals. It can be used to make simple songs.&lt;br /&gt;
* Train Stop can output the contents of the stopped train&#039;s cargo.&lt;br /&gt;
* Train Stop can be disabled using the circuit network. Trains will skip disabled Train Stops, allowing simple train control.&lt;br /&gt;
* Mining Drills can be turned on and off using the circuit network. They can also output the remaining expected resources.&lt;br /&gt;
* Pumpjacks can be turned on and off using the circuit network. They can also output the current oil mining rate.&lt;br /&gt;
* Added Modulo, Power, Left Bit Shift, Right Bit Shift, Bitwise AND, Bitwise OR and Bitwise XOR to the Arithmetic Combinator.&lt;br /&gt;
* Added additional operators to the Decider Combinator and Circuit Conditions.}}&lt;br /&gt;
&lt;br /&gt;
{{history|0.13.0|&lt;br /&gt;
* Many machines are now connectible to the circuit network.&lt;br /&gt;
* Wire disconnecting is incorporated into the latency hiding.&lt;br /&gt;
* Wires are now highlighted on entity mouseover.&lt;br /&gt;
* Reduced memory usage of circuit network.}}&lt;br /&gt;
&lt;br /&gt;
{{history|0.12.33|&lt;br /&gt;
* Fluid values are rounded to the closest value instead of rounding down when transmitted to circuit network.}}&lt;br /&gt;
&lt;br /&gt;
{{history|0.12.1|&lt;br /&gt;
* One can copy paste circuit network conditions between the [[inserter]], [[lamp]], [[pump]] and [[offshore pump]]. }}&lt;br /&gt;
&lt;br /&gt;
{{history|0.12.0|&lt;br /&gt;
* Improvements to circuit network connection, one can connect multiple wires of the same color to the same entity.&lt;br /&gt;
* The [[lamp]], [[storage tank]], [[pump]] and [[offshore pump]] can be connected to the circuit network.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{history|0.10.0|&lt;br /&gt;
* [[Blueprint]]s copy circuit network connections.}}&lt;br /&gt;
&lt;br /&gt;
{{history|0.8.3|&lt;br /&gt;
* Circuit network contents info has colored slots to specify the network it represents.}}&lt;br /&gt;
&lt;br /&gt;
{{history|0.1.0|&lt;br /&gt;
* Introduced}}&lt;br /&gt;
&lt;br /&gt;
[[Category: Circuit network]]&lt;/div&gt;</summary>
		<author><name>Jshi</name></author>
	</entry>
</feed>