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

Day 359 of 365 · Expert · Month 12: Masterpieces

Recap: quality

Recap quality: optimisation, debugging and robustness in one exercise – a copied legacy script becomes a subroutine that averages, counts failures and stays safe.

Lesson 22 min Week 52

What you learn today

  • Repeat optimisation
  • Combine debugging and robustness
  • Spot gaps

The second recap combines three weeks that belong together: optimisation, debugging and robustness. A script is only good when it fits on the chip, does the right thing and stays safe on bad days too.

Optimisation

LimitValuewhat helps
lines128select instead of jumps, subroutines, loops
characters4096short comments, game version
characters per line90wrap comments
instructions per tick128split long passes with a second yield

The most important rule: copied code is the most expensive code. Three rooms with the same logic are one subroutine and three calls, not the same twenty lines three times.

Debugging

The housing reports loud errors with name and line. Silent errors you find with probes, test cases and the simulator – and with the knowledge of where they live: Sum instead of Average, NaN, −inf, Celsius instead of Kelvin, the forgotten j start.

Robustness

Every sensor may be missing. The only question is what happens then: detect NaN, report, stay safe. And after a restart the chip knows nothing any more – whatever it must remember lives in the device or in a Logic Memory. For a heater the device itself is enough:

lbn on HEIZUNG name On Average      # the state lives in the device
snan tmp on
select on tmp 0 on               # heater missing: off

That way no room needs a register of its own for its state, and a restart simply takes over whatever the heater is doing right now.

Finding gaps

Take a script from your base and go through it with this page. Does it fit on the chip with room to spare? Does it have a test case for every sensor failure? Do you know what it does after a restart? Every “don't know” is a gap – and a day you should read once more.

Tip

The exercise has exactly the three kinds of errors that occur most often in old scripts: copied blocks, Sum for temperatures and not a word about what happens without a sensor.

Exercise

Task

The old version controls two rooms with copied code and Sum. Rebuild it: three rooms “R1”, “R2”, “R3”, each with sensor(s) and heater of the same name, on below 18 °C, off above 21 °C, the mean of all sensors of a room. One subroutine for all rooms. If a room's sensor is missing, its heater is off, and the display “Raeume_Fehler” counts the rooms without a sensor.

Hints

Hint 1

Main part: faults to 0, three times move name HASH("R…") and jal raum, then the display.

Hint 2

In the subroutine Average instead of Sum, snan counts the missing sensor.

Hint 3

Read the state back from the heater, 0 on NaN. The hysteresis switches off on its own with NaN.

Quiz

3 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