What you learn today
- Recognise the layout of a script
- Use templates and the library
- Trace code line by line
Kolja from the neighbouring depot gave you his heating chip. A few dozen lines, names you do not know. Before you install it, you have to understand it. You do not read other people's code like a novel from top to bottom, but in a fixed order.
1. Recognise the layout
Almost every good script has the same parts:
| Part | how you recognise it |
|---|---|
| header | comment at the very top: what the script does |
| settings block | define lines with hashes, limits, times |
| register plan | alias lines |
| preparation | lines before the start label, such as move counter 0 |
| main loop | from the start label with yield to j start |
| subroutines | labels after the main loop, ending with j ra |
Read the define lines first. They tell you which devices the script expects and which numbers you may adjust. The alias lines are the list of variables.
2. Pick out the device names
Every HASH("…") in the body is a device name. Write them down. If your device has a different name, lbn does not find it, and depending on the batch mode you get NaN, 0 or −infinity.
lbn temp SENSOR HASH("Raum1") Temperature Average
sbn HEATER HASH("Heizung1") On heat
Here the script expects a gas sensor “Raum1” and a heater “Heizung1”.
3. Trace line by line
Now play one pass through in your head. Write the registers as columns on a piece of paper and enter line by line what changes. At every jump you ask: is the condition true right now?
| Line | temp | tmp | heat |
|---|---|---|---|
lbn temp … | 291.15 | 0 | 0 |
slt tmp temp UPPER | 291.15 | 1 | 0 |
and heat heat tmp | 291.15 | 1 | 0 |
slt tmp temp LOWER | 291.15 | 1 | 0 |
or heat heat tmp | 291.15 | 1 | 1 |
It is faster in the simulator of the IC10 coder: paste the code, create the devices, run step by step and watch the registers.
Templates and library
The IC10 coder has two good sources of other people's code. Under Templates you find ready-made building blocks in the workshop style, such as “Hold temperature (hysteresis)” or “Lights on presence”. The Library holds scripts that other players have published. In the game itself you find saved scripts in the library of the IC editor.
Before you install other people's code, check three things: device names, limits and the direction on a failure. A script that fits Kolja's base can leave your heater running for good.
First change only the settings block and the names, not the body. Well-written scripts are built exactly for that.
Diagram
Exercise
Task
Kolja's heating chip is in the editor. Read it and adapt it to your workshop:
- your gas sensor is called “Werkstatt”
- your wall heater is called “Werkstattheizung”
- control between 18 °C (on, 291.15 K) and 20 °C (off, 293.15 K)
The rest of the script stays as it is.
Hints
Hint 1
The limits are in the settings block: LOWER and UPPER.
Hint 2
The device names are in the body inside HASH("…").
Hint 3
Check with one pass in your head: at 17 °C heat must become 1.
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