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

Day 95 of 365 · Advanced · Month 4: Network in detail

The −inf trap of Maximum

Without a matching device Maximum returns −infinity and Minimum 0. Both look like a real value. You guard against it with Count or a comparison with ninf.

Lesson 13 min Week 14

What you learn today

  • Maximum without a match returns ninf
  • Minimum returns 0
  • Guard with Count

Two sensors hang in the battery room. Cooling should start as soon as one of them reports more than 35 °C. So Maximum. That works until someone removes both sensors for a rebuild. Then the display shows “−Infinity”, the cooling stands still, and nobody notices.

Three answers to “no match”

Moderesult without a device
AverageNaN
Minimum0
Maximum−infinity (ninf)

That is how the game code is built: Minimum catches the empty case and returns 0, Maximum does not. It keeps its start value of −infinity.

Why −infinity is dangerous

−infinity is a number, not NaN. snan does not trigger, and every comparison behaves perfectly normally:

lbn highest SENSOR HASH("Akkuraum") Temperature Maximum
sgt cool highest ON           # -inf > 308.15: never true

The cooling stays off. For an overheating battery room that is the wrong direction. If you keep calculating, it does not get better: −infinity minus 273.15 stays −infinity, and the display shows nonsense.

Minimum has its trap too: 0 is a valid reading. 0 K does not happen, but a pressure of 0 kPa does. Without a device a pressure minimum looks like a vacuum.

Guarding with Count

Before you believe the maximum, you ask whether any device is there at all:

lb count SENSOR PrefabHash Count
seqz missing count            # 1 = no sensor
or cool cool missing          # no sensor: cool

Count ignores the name, you know that since yesterday. If other gas sensors hang on the network, take the sum over PrefabHash divided by the hash. Or compare with ninf directly:

seq missing highest ninf      # -inf only happens without a sensor

The comparison with ninf is exact and works because −infinity is exactly equal to −infinity.

Warning

Never rely on Maximum reporting anything sensible when the sensors are missing. Every line that uses the maximum needs a guard in front of it.

Tip

For the display replace the empty case with a clear value such as −999. A player understands “−999” faster than “−Infinity”.

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.
Without a match Average gives NaN, Minimum 0, Maximum −infinity. Only NaN is caught by snan.

Exercise

Task

Two gas sensors “Akkuraum” (there are no other gas sensors on the network). The code in the editor already uses Maximum but is not guarded.

  • wall cooler “Akkukuehler”: on above 35 °C, off below 30 °C (highest temperature)
  • if no sensors are present: cooler on, flashing light “Akkuwarnung” on
  • LED “Akkutemp” shows the highest temperature in °C, without a sensor −999

Hints

Hint 1

lb count SENSOR PrefabHash Count, then seqz missing count.

Hint 2

Add or cool cool missing to the hysteresis.

Hint 3

Switch the warning lamp directly with missing, the display with select c missing NOVALUE c.

Quiz

4 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