An IC Housing has six pins, d0 to d5. For a small controller that is enough. But once ten vents, three sensors and a display join in, it gets tight. The solution: address devices by their name. That reaches every device on the data network – no pins needed.
This article sums up the essentials. The IC10 academy goes deeper, with exercises.
The two instructions
| Instruction | Form | Effect |
|---|---|---|
lbn | lbn r? deviceHash nameHash logicType batchMode | reads a value from all matching devices |
sbn | sbn deviceHash nameHash logicType r? | writes a value to all matching devices |
Matching means: same device type (prefab hash) and same name.
The device hash
Every device has a fixed prefab hash. For the Active Vent it is -1129453144. You find the hash at the top of every device page in this wiki, with a copy button, or in the Hash lookup.
The name
You give the device its name in game with the Labeller. In the program HASH("…") turns it into a number. HASH is replaced when the script is saved, so it may appear wherever a number may appear – including after define. Names with spaces are fine:
define NAME HASH("Storage Vent")
Give all vents in a room the same name. A single sbn then switches all of them at once.
The batch mode when reading
When several devices match, the batch mode decides what lbn returns:
| Mode | Number | Result | when no device matches |
|---|---|---|---|
| Average | 0 | average | NaN |
| Sum | 1 | sum | 0 |
| Minimum | 2 | smallest value | 0 |
| Maximum | 3 | largest value | −infinity |
| Count | 4 | number of devices | 0 |
For readings, always use 0 (Average). With Sum a mistake only shows once a second device with the same name is built: two sensors at 400 K each suddenly read 800 K.
Average returns NaN when no device with that name is found – after a typo in the name, for example. NaN silently spreads through every calculation. So catch it right away:
lbn pressure SENSOR NSENSOR Pressure 0
bnan pressure start
What else you need to know
- Batch instructions only work over the data cable network, not over the pins.
- If the IC housing has no data network at all, the chip stops with an error.
- If a device cannot read or write the logic type, the chip stops as well. Which values a device knows is listed on its page under “IC10 and logic”.
- Every main loop needs a
yield. Device values only change once per tick (0.5 s). - If the program runs past its last line, the chip stays stopped for good. That is why every loop ends with
j start.
A complete example: holding room pressure
A Gas Sensor named “Storage Sensor” measures the pressure. If it drops below 95 kPa, all vents named “Storage Vent” blow air into the room until 101 kPa is reached.
# Hold room pressure: vents by name
define SENSOR -1252983604 # Gas Sensor (StructureGasSensor)
define VENT -1129453144 # Active Vent (StructureActiveVent)
define NSENSOR HASH("Storage Sensor") # name of the sensor
define NVENT HASH("Storage Vent") # name of the vents
define PMIN 95 # kPa, switch on below
define PMAX 101 # kPa, switch off above
alias pressure r0
alias run r1
alias low r2
alias high r3
# --- 1. Once at start: set the direction ---
sbn VENT NVENT Mode 0 # 0 = outward (into the room)
start:
yield
# --- 2. Read pressure and switch ---
lbn pressure SENSOR NSENSOR Pressure 0
bnan pressure start # no sensor with this name
slt low pressure PMIN
sgt high pressure PMAX
select run low 1 run # too little pressure: on
select run high 0 run # enough pressure: off
sbn VENT NVENT On run
j start
How to read it:
- The
definelines keep all numbers in one place. For a different pressure you only changePMINandPMAX. - The
aliaslines give the registers readable names. Modeis written only once, before the loop. There is a reason: every write toModeresets the active vent's target pressures, even when the same value is already set. In mode 0 that meansPressureExternal= 101.325 kPa andPressureInternal= 0. If the line sat inside the loop, a target pressure of your own would be gone after one tick.sltandsgtsetlowandhighto 1 or 0.- The two
selectlines build a hysteresis: between 95 and 101 kPa the last state is kept. Without it the vents would keep switching on and off.
A vent you build after the chip has started does not get the Mode from section 1. Check its direction in game or restart the chip.
Every device page in this wiki also has a short example in the same style that addresses exactly that device by name.
Continue in the academy
- IC10 academy – the full course
- IC10 academy: devices by name
- IC10 academy: batch modes
- IC10 academy: define and alias
- Try code right away: IC10 editor