We are currently experiencing issues with email delivery; this is being resolved as quickly as possible.

stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Batch modes and the NaN trap

Chapter 4 · Data network

Batch modes and the NaN trap

Average, Sum, Minimum, Maximum, Count – and what happens when no device answers.

Lesson 11 of 18 10 min

lbn reads many devices at once. How they become one number is decided by the last operand, the batch mode:

ModeNumberResultif no device matches
Average0meanNaN
Sum1sum0
Minimum2smallest value0
Maximum3largest value−infinity
Count4number of devices0

Average for readings

Temperature, pressure, fill level: always Average. With Sum the mistake only shows when a second sensor with the same name appears – then 2 × 300 K add up to 600 K and your heater thinks the storage is on fire.

Sum fits quantities that truly add up: power of all solar panels, number of items in all lockers.

The NaN trap

If Average finds no matching device – misspelt name, cut cable, removed sensor – the result is NaN (“not a number”). Every calculation with NaN gives NaN again, every comparison is false. The program silently carries on with nonsense.

Catch it with snan (1 if NaN) or bnan (jumps on NaN):

lbn temp SENSOR HASH("Room") Temperature Average
snan missing temp     # 1 = no sensor found
bnan temp fault       # or jump away right away
Warning

With lbn, Count counts every device of the type – the game ignores the name for it. Do not rely on it for “how many have this name?”.

Diagram

Three readings, five batch modes Sensor “Raum” 300 K Sensor “Raum” 310 K Sensor “Raum” 250 K lbn Average 286.67 Sum 860 Minimum 250 Maximum 310 Count 3 Sum on temperatures: 860 K – the heater thinks there is a fire.
Three sensors, five batch modes: the last operand of lb/lbn decides how many readings become one.

Exercise

Task

The network holds three station batteries named “Akku” and one named “Reserve” (prefab StructureBattery, fill level in the LogicType Ratio, 0 to 1).

In an endless loop:

  • r0 = average fill level of the “Akku” batteries
  • r1 = the lowest fill level of the “Akku” batteries
  • r2 = 1 if no “Akku” battery is found (NaN), otherwise 0

Hints

Hint 1

Two lbn with the same type and name, only the batch mode differs.

Hint 2

snan missing avg puts 1 into missing when the average is NaN.

Esc
↑ ↓ selectEnter open/ opens search anywhere