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

Day 307 of 365 · Expert · Month 11: Optimisation and debugging

Project: optimise

A script with more than 128 lines has to go into the chip: table and loop instead of repeating four times, behaviour unchanged, lines, characters and steps measured before and after.

Project 45 min Week 44

What you learn today

  • Bring an oversized script below the limits
  • Behaviour unchanged
  • Measure before and after

A colleague wrote a script for four rooms: each room has a heater with hysteresis and an alarm light, plus a display with the number of alarms. It is well commented, it works in the simulator – and it cannot be loaded. It has more than 128 lines.

The setup

DevicePrefabNames
Gas sensorsStructureGasSensor“Raum1” to “Raum4”
Wall heatersStructureWallHeater“Raum1” to “Raum4”
Alarm lightsStructureWallLight“Raum1” to “Raum4”
LED displayStructureConsoleLED5“Alarme”

The rules

  1. Each room's heater on below 20 °C, off above 24 °C. The chip reads the previous state back from the heater.
  2. The room's alarm light on below 15 °C, above 35 °C or without a sensor.
  3. The display shows how many rooms have an alarm.

Measuring before and after

Before you optimise, you measure. Afterwards you measure again. For the starter code and a solution with a name table it looks like this:

beforeafter
lines13345
characters3,7891,041
steps per tick11878

“Steps per tick” counts every line the chip runs through between two yield – comments in the loop included.

The lines shrink to a third, the steps per tick only to two thirds. In the starter code the many comment lines cost steps every tick – they disappear. In return the loop adds label, counter and jump back, four times per tick. Both are below 128, for this plant that is enough. With twelve rooms the loop would need around 220 steps and would have to run in portions as on Thursday.

Milestones

  1. Each room heats with hysteresis, independently of the others.
  2. Each room reports cold and heat on its light.
  3. The display counts the rooms with an alarm.
  4. A missing sensor switches off its room's heater and reports an alarm.
Tip

Work in small steps: first the name table, then the loop with only the heater part, test, then the alarm. Whoever rebuilds everything at once then searches for the bug in 40 lines instead of five.

Warning

“Behaviour unchanged” is the most important part of the task. A shorter script that leaves the heater on with a missing sensor is worse than one that is too long.

Diagram

The three limits of a program Lines 74/128 Characters 3990/4096 Width 97/90 Comments and blank lines count fully. The longest line here is too wide.
Before, four written-out blocks; after, one loop over a name table.

Project task

Task

The starter code has 133 lines and cannot be loaded. Bring it below 128 lines with a name table and a loop. All four rules above must still hold.

Milestones

  1. Milestone 1: heater per room
  2. Milestone 2: alarm per room
  3. Milestone 3: counting alarms
  4. Milestone 4: sensor missing

Hints

Hint 1

Before start: four poke with HASH("Raum1") to HASH("Raum4").

Hint 2

One room's block becomes the loop body: replace HASH("RaumN") with the register name.

Hint 3

The comments per room go – one comment above the loop is enough.

Quiz

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

Complete the day

  • Passed all milestones of the project
  • 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