What you learn today
- define and alias consistently
- Sections
- Comments
You have known the workshop rules since month 1. Today they are all together in one place, each with its reason. Whoever knows the reason also knows when a rule exceptionally does not fit.
The rules
| Rule | Reason |
|---|---|
define for every prefab hash and every constant, with a comment | numbers in the body have no name, one change in one place is enough |
alias for every register, block after the defines | tRoom instead of r3 – you still know later what is in it |
devices via lbn/sbn with HASH("Name") | no 6-pin limit, devices are found by their name in the game |
batch mode Average | two sensors with the same name must not be added up |
sections # --- 1. Measure --- | the flow is visible at a glance |
| only labels as jump targets | line numbers shift with every new line |
yield in every main loop | one pass per tick, fresh readings |
| endless loop | otherwise the chip stops after one pass |
| Kelvin literal with Celsius in the comment | the chip calculates in Kelvin, you think in Celsius |
| no deprecated instructions | l and s can do everything ld and sd could |
Comments and names
The workshop writes its comments in German, but without special characters: the checker in the IC10 coder warns that the game turns umlauts in comments into “?”. So “Kuehlung” instead of “Kühlung”. For device names in HASH("…") this applies anyway: the hash is computed from the characters, and an umlaut no longer matches the name on the device.
What it looks like
# --- Air watch lab ---
define SENSOR HASH("StructureGasSensor") # gas sensor
define GRENZE 0.02 # 2 % CO2, alarm above
alias co2 r0
alias alarm r1
start:
yield
# --- 1. Measure ---
lbn co2 SENSOR HASH("Labor") RatioCarbonDioxide Average
# --- 2. Alarm ---
sgt alarm co2 GRENZE
j start
Style costs characters. In a long script the comments are usually the reason why the 4096 characters get tight. Then shorten the comments, not the defines – a short comment is better than a nameless number.
Diagram
Exercise
Task
The starter code is a working air watch from the early days: pins, raw numbers, a jump to line 0, no NaN guard. Rebuild it according to the guide. Sensor “Labor”, display “Labor_CO2” (CO₂ in percent with one decimal, -1 without sensor, colour green or red on alarm), flashing light “Labor_Alarm” (on above 2 % CO₂ and with a missing sensor). Every number gets a define.
Hints
Hint 1
Pins out: lbn/sbn with the three names and defines for the three prefabs.
Hint 2
0.02, 1000, 10 and -1 also get a define, plus Color.Green and Color.Red.
Hint 3
j 0 becomes a label, and snanz plus select catch the missing sensor.
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