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

Day 85 of 365 · Beginner · Month 3: First systems

Reading other people's code

You read other people's code in a fixed order: layout, settings block, device names, then line by line. Afterwards you adapt it to your base.

Lesson 14 min Week 13

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:

Parthow you recognise it
headercomment at the very top: what the script does
settings blockdefine lines with hashes, limits, times
register planalias lines
preparationlines before the start label, such as move counter 0
main loopfrom the start label with yield to j start
subroutineslabels 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?

Linetemptmpheat
lbn temp …291.1500
slt tmp temp UPPER291.1510
and heat heat tmp291.1510
slt tmp temp LOWER291.1510
or heat heat tmp291.1511

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.

Warning

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.

Tip

First change only the settings block and the names, not the body. Well-written scripts are built exactly for that.

Diagram

Program layout in the proven style # --- Heat warning --- define LIMIT 303.15 # 30 C define SENSOR HASH("…") alias temp r0 alias hot r1 start: yield … j start 1 · define everything tunable 2 · alias names for registers 3 · main loop with yield, endless
Header, settings block, register plan, main loop: if you know the layout, you quickly find the places to adapt in any script.

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

Esc
↑ ↓ selectEnter open/ opens search anywhere