stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 36

Day 36 of 365 · Beginner · Month 2: Order and data network

Batch modes and the NaN trap

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

Lesson 10 min Week 6

What you learn today

  • Average, Sum, Minimum, Maximum, Count
  • Average for measurements
  • NaN when a device is missing

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.

Quiz

5 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere