<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.mutigeraffe.com/index.php?action=history&amp;feed=atom&amp;title=BlockFactory%3ASignals_and_Programmable_Interface</id>
	<title>BlockFactory:Signals and Programmable Interface - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.mutigeraffe.com/index.php?action=history&amp;feed=atom&amp;title=BlockFactory%3ASignals_and_Programmable_Interface"/>
	<link rel="alternate" type="text/html" href="https://wiki.mutigeraffe.com/index.php?title=BlockFactory:Signals_and_Programmable_Interface&amp;action=history"/>
	<updated>2026-10-19T22:10:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.mutigeraffe.com/index.php?title=BlockFactory:Signals_and_Programmable_Interface&amp;diff=307&amp;oldid=prev</id>
		<title>Maintenance script: BlockFactory wiki</title>
		<link rel="alternate" type="text/html" href="https://wiki.mutigeraffe.com/index.php?title=BlockFactory:Signals_and_Programmable_Interface&amp;diff=307&amp;oldid=prev"/>
		<updated>2026-10-19T07:05:30Z</updated>

		<summary type="html">&lt;p&gt;BlockFactory wiki&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page covers two kinds of signals. &amp;#039;&amp;#039;&amp;#039;Rail signals&amp;#039;&amp;#039;&amp;#039; split a rail network into blocks so that several trains can share it. The &amp;#039;&amp;#039;&amp;#039;signal network&amp;#039;&amp;#039;&amp;#039; lets your factory react to itself: chests report their contents, tanks their fill level, and you switch Grabbers, pumps, boilers, lamps and Train Stops on and off. Instead of logic gates you write small programs in a &amp;#039;&amp;#039;&amp;#039;Programmable Interface&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Rail Signal and Chain Signal ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Name !! Epoch !! Unlocked by !! Size !! Recipe&lt;br /&gt;
|-&lt;br /&gt;
| [[File:BlockFactory_Rail_Signal.png|32px]] || &amp;#039;&amp;#039;&amp;#039;Rail Signal&amp;#039;&amp;#039;&amp;#039; || 2 || Rail Signals || 1 × 1 || 5 Steel Plate + 1 Electronic Circuit&lt;br /&gt;
|-&lt;br /&gt;
| [[File:BlockFactory_Chain_Signal.png|32px]] || &amp;#039;&amp;#039;&amp;#039;Chain Signal&amp;#039;&amp;#039;&amp;#039; || 2 || Rail Signals || 1 × 1 || 5 Steel Plate + 1 Electronic Circuit&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Without signals the whole rail network is a single block, and only one train can move through it safely. Signals cut the network into blocks, and &amp;#039;&amp;#039;&amp;#039;only one train may be in a block at a time&amp;#039;&amp;#039;&amp;#039;. A train never drives into rail cells that another train occupies, signals or not.&lt;br /&gt;
&lt;br /&gt;
* Place a signal right beside the track, with its lenses facing the oncoming train. It guards the rail cell next to it, for trains coming from the side its lenses face. Trains going the other way pass it unchecked. Place it so that it touches only the rail it should guard.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Rail Signal:&amp;#039;&amp;#039;&amp;#039; green when the block behind it is free, red when another train is in it or has reserved it. A train waits in front of a red signal.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Chain Signal:&amp;#039;&amp;#039;&amp;#039; lets a train through only if every block along its way is free, up to and including the block behind the next Rail Signal. Put Chain Signals in front of crossings and junctions, so that trains never stop in the middle of one.&lt;br /&gt;
* Signals update their lights once per second.&lt;br /&gt;
&lt;br /&gt;
For trains, stops and schedules see [[BlockFactory:Railways|Railways]].&lt;br /&gt;
&lt;br /&gt;
== Signal network ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Name !! Epoch !! Unlocked by !! Size !! Recipe&lt;br /&gt;
|-&lt;br /&gt;
| [[File:BlockFactory_Signal_Cable.png|32px]] || &amp;#039;&amp;#039;&amp;#039;Signal Cable&amp;#039;&amp;#039;&amp;#039; || 3 || Circuit Network || tool || 1 Electronic Circuit + 5 Copper Cable&lt;br /&gt;
|-&lt;br /&gt;
| [[File:BlockFactory_Programmable_Interface.png|32px]] || &amp;#039;&amp;#039;&amp;#039;Programmable Interface&amp;#039;&amp;#039;&amp;#039; || 3 || Programmable Interface || 1 × 1 || 5 Advanced Circuit + 5 Electronic Circuit + 5 Steel Plate&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Wiring ===&lt;br /&gt;
* Hold the &amp;#039;&amp;#039;&amp;#039;Signal Cable&amp;#039;&amp;#039;&amp;#039; and right-click a building, then a second one. A green wire connects them. The cable is a tool and is not used up.&lt;br /&gt;
* A wire reaches at most &amp;#039;&amp;#039;&amp;#039;10 blocks&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
* Right-click the same building twice to remove all its wires.&lt;br /&gt;
* You can only wire buildings of your own team.&lt;br /&gt;
&lt;br /&gt;
All buildings joined by wires form one network. Each tick, a network adds up the signals of all its members.&lt;br /&gt;
&lt;br /&gt;
=== What buildings report ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Signal !! Who reports it !! Value&lt;br /&gt;
|-&lt;br /&gt;
| an item ID, e.g. &amp;lt;code&amp;gt;BF_Iron_Plate&amp;lt;/code&amp;gt; || chests and other buildings that store items, such as Gun Towers || how many of that item it holds&lt;br /&gt;
|-&lt;br /&gt;
| a fluid name, e.g. &amp;lt;code&amp;gt;Crude_Oil&amp;lt;/code&amp;gt; || Storage Tanks and every building with fluid tanks || units in its tanks&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;power&amp;lt;/code&amp;gt; || every building on a power grid || how well that grid is supplied, in percent (100 = enough power)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;train&amp;lt;/code&amp;gt; || Train Stop || 1 while a train is halted there, otherwise 0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;unrest&amp;lt;/code&amp;gt; || the world, once per network || the current unrest in percent (see [[BlockFactory:Enemies|Enemies]])&lt;br /&gt;
|-&lt;br /&gt;
| your own names || Programmable Interfaces || whatever their program sets with &amp;lt;code&amp;gt;out&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
* Values of the same name add up. Every wired building on a grid adds its own &amp;lt;code&amp;gt;power&amp;lt;/code&amp;gt; value, so wire only one of them if you want a plain percentage.&lt;br /&gt;
* Item signals use the item&amp;#039;s ID: &amp;lt;code&amp;gt;BF_&amp;lt;/code&amp;gt; plus the name with underscores, for example &amp;lt;code&amp;gt;BF_Coal&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;BF_Advanced_Circuit&amp;lt;/code&amp;gt;. The [[BlockFactory:Items|Items]] page lists all IDs.&lt;br /&gt;
* Fluid signals are &amp;lt;code&amp;gt;Water&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Steam&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Crude_Oil&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Heavy_Oil&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Light_Oil&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Petroleum_Gas&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Lubricant&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Sulfuric_Acid&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Machines that burn fuel do not report their slots, only their fluid tanks.&lt;br /&gt;
&lt;br /&gt;
=== What you can switch ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Building !! Listens to&lt;br /&gt;
|-&lt;br /&gt;
| Coal Grabber, Grabber T1, T2, T3, Mass Grabber, Long Grabber || &amp;lt;code&amp;gt;grabber&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Water Boiler || &amp;lt;code&amp;gt;boiler&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Water Pump, Oil Pumpjack || &amp;lt;code&amp;gt;pump&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Train Stop || &amp;lt;code&amp;gt;stop&amp;lt;/code&amp;gt; (trains do not head for a stop that is off)&lt;br /&gt;
|-&lt;br /&gt;
| Lamp || &amp;lt;code&amp;gt;lamp&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Nuclear Reactor, Heat Exchanger || &amp;lt;code&amp;gt;on&amp;lt;/code&amp;gt; only&lt;br /&gt;
|}&lt;br /&gt;
A wired building runs only while its signal is &amp;#039;&amp;#039;&amp;#039;greater than 0&amp;#039;&amp;#039;&amp;#039;. If its own signal is missing from the network, it listens to &amp;lt;code&amp;gt;on&amp;lt;/code&amp;gt; instead, which switches everything at once. If neither signal is in the network, it runs as if it had no wire.&lt;br /&gt;
&lt;br /&gt;
== Programmable Interface ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Use&amp;#039;&amp;#039;&amp;#039; the interface to open its editor: a code field, a &amp;#039;&amp;#039;&amp;#039;Save&amp;#039;&amp;#039;&amp;#039; button, three example programs, and a live view of the network&amp;#039;s signals and of the interface&amp;#039;s outputs. &amp;#039;&amp;#039;&amp;#039;Save&amp;#039;&amp;#039;&amp;#039; checks the program; if something is wrong, the status line names the line and the problem. The interface itself shows whether its program runs or has stopped with an error.&lt;br /&gt;
&lt;br /&gt;
The program runs &amp;#039;&amp;#039;&amp;#039;once per tick&amp;#039;&amp;#039;&amp;#039; (30 times per second) with the signals its network had in the previous tick. Its outputs enter the network in the next tick.&lt;br /&gt;
&lt;br /&gt;
=== Statements ===&lt;br /&gt;
One statement per line. Everything after &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt; is a comment. Empty lines are ignored, and indentation does not matter.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Statement !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;name = expression&amp;lt;/code&amp;gt; || set a variable&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;out name = expression&amp;lt;/code&amp;gt; || send the signal &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; into the network&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;if expression&amp;lt;/code&amp;gt; … &amp;lt;code&amp;gt;elif expression&amp;lt;/code&amp;gt; … &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; … &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt; || run the lines below only if the value is not 0; &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; are optional, &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt; is required. Blocks can be nested.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Values and names ===&lt;br /&gt;
* All values are whole numbers. &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; drops the remainder, &amp;lt;code&amp;gt;%&amp;lt;/code&amp;gt; gives it. Dividing by 0 is an error.&lt;br /&gt;
* &amp;lt;code&amp;gt;$name&amp;lt;/code&amp;gt; reads a network signal; a missing signal reads as 0.&lt;br /&gt;
* A plain &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; reads a variable. Variables start at 0 and keep their value from tick to tick, until you save the program again or the server restarts.&lt;br /&gt;
* Outputs are set fresh in every run: an &amp;lt;code&amp;gt;out&amp;lt;/code&amp;gt; line that does not run in a tick sends nothing in that tick. If several &amp;lt;code&amp;gt;out&amp;lt;/code&amp;gt; lines set the same name, the last one counts.&lt;br /&gt;
* Names start with a letter or &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt; and may contain letters, digits and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;. They are case sensitive. The keywords &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;and&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;or&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;not&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;out&amp;lt;/code&amp;gt; are not, and cannot be used as variable names.&lt;br /&gt;
&lt;br /&gt;
=== Operators ===&lt;br /&gt;
From strongest to weakest binding:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Operators !! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;( )&amp;lt;/code&amp;gt; || grouping&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;-x&amp;lt;/code&amp;gt; || negative&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;%&amp;lt;/code&amp;gt; || multiply, divide, remainder&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;-&amp;lt;/code&amp;gt; || add, subtract&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;!=&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;&amp;amp;lt;&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;&amp;amp;lt;=&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;&amp;amp;gt;&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;&amp;amp;gt;=&amp;lt;/code&amp;gt; || give 1 (true) or 0 (false). Only one comparison per term: write &amp;lt;code&amp;gt;a &amp;amp;lt; b and b &amp;amp;lt; c&amp;lt;/code&amp;gt;, not &amp;lt;code&amp;gt;a &amp;amp;lt; b &amp;amp;lt; c&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;not&amp;lt;/code&amp;gt; || 1 if the value is 0, otherwise 0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;and&amp;lt;/code&amp;gt; || 1 if both sides are not 0&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;or&amp;lt;/code&amp;gt; || 1 if at least one side is not 0&lt;br /&gt;
|}&lt;br /&gt;
Because &amp;lt;code&amp;gt;not&amp;lt;/code&amp;gt; binds weaker than comparisons, &amp;lt;code&amp;gt;not $train == 1&amp;lt;/code&amp;gt; means &amp;quot;not (train equals 1)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
There are no other functions, loops or text values. A program may have at most 200 lines. An error while running (division by zero, too many steps in one tick) stops the program until you save it again.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
Run the boilers only while the wired coal chest holds more than 20 Coal (one of the built-in examples):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Boilers by coal in the chest&lt;br /&gt;
out boiler = $BF_Coal &amp;gt; 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open a station only when the iron chest next to it runs low. Wire the interface to the chest and the Train Stop; trains heading for that stop name go elsewhere while it is closed:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Station on demand&lt;br /&gt;
if $BF_Iron_Plate &amp;lt; 200&lt;br /&gt;
  out stop = 1&lt;br /&gt;
else&lt;br /&gt;
  out stop = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep an oil tank between 5,000 and 20,000 units. Wire the interface to the Storage Tank and the Oil Pumpjacks. The variable remembers whether the pumps are filling, so they do not flicker on and off at a single threshold:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if $Crude_Oil &amp;lt; 5000&lt;br /&gt;
  filling = 1&lt;br /&gt;
elif $Crude_Oil &amp;gt; 20000&lt;br /&gt;
  filling = 0&lt;br /&gt;
end&lt;br /&gt;
out pump = filling&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A counter that sends a one-tick &amp;lt;code&amp;gt;pulse&amp;lt;/code&amp;gt; every 30 ticks (once per second):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t = t + 1&lt;br /&gt;
if t &amp;gt;= 30&lt;br /&gt;
  t = 0&lt;br /&gt;
  out pulse = 1&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Light the wired lamps as an alarm once the unrest reaches 20 %:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
out lamp = $unrest &amp;gt;= 20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Wirecutter ==&lt;br /&gt;
[[File:BlockFactory_Wirecutter.png|32px]] The &amp;#039;&amp;#039;&amp;#039;Wirecutter&amp;#039;&amp;#039;&amp;#039; (Start, 2 Iron Plate + 1 Wood) is for power poles, not for signal wires. Right-click a power pole, then a second one, to cut the cable between them or put it back. This is only for looks: the poles stay connected to the grid. See [[BlockFactory:Power|Power]].&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[BlockFactory:Railways|Railways]]&lt;br /&gt;
* [[BlockFactory:Power|Power]]&lt;br /&gt;
* [[BlockFactory:Fluids|Fluids]]&lt;br /&gt;
* [[BlockFactory:Grabbers|Grabbers]]&lt;br /&gt;
&lt;br /&gt;
{{BlockFactory Nav}}&lt;/div&gt;</summary>
		<author><name>Maintenance script</name></author>
	</entry>
</feed>