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

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

Documenting scripts

Documenting scripts: a header comment with purpose and version, the list of all devices with name and prefab, and settings with unit, range and effect.

Lesson 16 min Week 47

What you learn today

  • Header comment
  • List device names
  • Explain settings

A fellow player rebuilds your store light and reports: “Does not work.” After ten minutes it turns out that his motion sensor is called “Lagerraum”. One line of documentation would have prevented that. Documentation is not for you today, but for you in half a year and for everyone who takes over your script.

The header comment

At the very top stands what you need to know before building anything:

# === Store light ===
# Purpose: light in the store on motion, with run-on
# Version 3, Dominik1199
# Devices (name / prefab / job):
#   Lager / StructureMotionSensor / motion
#   Lager / StructureWallLight / light
#   Version / StructureConsoleLED5 / shows VERSION

Purpose, version and author in one line each. Below it the device list: every name the script looks for via HASH("…"), with prefab and job. Whoever works through the list has named the setup correctly – including the fellow player with the “Lagerraum”.

Explaining settings

A define comment answers three questions: unit, sensible range, effect.

define NACHLAUF 10 # passes of light after motion, 10 = 5 s

“10” on its own says nothing. “Passes” gives the unit, “10 = 5 s” translates it into something you can imagine. For temperatures Celsius stands next to the Kelvin value, for ratios the percentage.

When characters get tight

A good header quickly costs 300 to 400 of the 4096 characters. If it gets tight, there are two versions: the long version with all comments lives in your library, the IC10 coder's game version strips comments and blank lines and runs in the chip. The long version is the original – changes are always made there, and the game version is generated again afterwards.

Tip

Also write the version as define VERSION into the code and let the chip show it. Comments disappear in the game version, the version on the display stays.

Exercise

Task

Write the store light with a complete header: purpose, version, device list, explained settings. The motion sensor “Lager” reports motion via Activate (it covers exactly the 2 m cell it sits in and every movable object in it – even a tool put down there keeps it at 1), the light “Lager” then stays on for another 10 passes. At start the display “Version” shows define VERSION 3. If the sensor is missing, the light stays on. The check tests the behaviour – you check the header yourself.

Hints

Hint 1

A counter rest: set it to NACHLAUF on motion, otherwise decrease it by 1 every pass, never below 0.

Hint 2

Light on while rest is above 0: sgtz.

Hint 3

If the sensor is missing, Activate is NaN – treat it as motion with snan and select.

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