lbn reads many devices at once. How they become one number is decided by the last operand, the batch mode:
| Mode | Number | Result | if no device matches |
|---|---|---|---|
Average | 0 | mean | NaN |
Sum | 1 | sum | 0 |
Minimum | 2 | smallest value | 0 |
Maximum | 3 | largest value | −infinity |
Count | 4 | number of devices | 0 |
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
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
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” batteriesr1= the lowest fill level of the “Akku” batteriesr2= 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.