We are currently experiencing issues with email delivery; this is being resolved as quickly as possible.

stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. define and alias: code with names

Chapter 3 · Decisions & style

define and alias: code with names

Fixed values and registers get names – the layout Dominik uses in every chip.

Lesson 9 of 18 10 min

sgt r1 r0 303.15 – what was r1 again? And why 303.15? In three weeks nobody knows. Two instructions bring order.

define: names for fixed numbers

define LIMIT 303.15   # 30 C

Wherever LIMIT appears afterwards, the chip uses 303.15. A define costs no register and never changes. Perfect for set points, thresholds and later for device types.

alias: names for registers and pins

alias temp r0
alias sensor d0

Now you may write temp instead of r0 and sensor instead of d0. An alias on a pin also shows up at the housing’s screws.

The layout that works

# --- Heat warning ---
# --- 1. Settings ---
define LIMIT 303.15     # 30 C
# --- 2. Registers and devices ---
alias sensor d0
alias light d1
alias temp r0
alias hot r1
# --- 3. Main loop ---
start:
yield
l temp sensor Temperature
sgt hot temp LIMIT
s light On hot
j start

First define, then alias, then the main loop with yield. Every number you might want to tune later sits at the top with a comment – the body only contains names.

Tip

Comments count fully towards the 4096-character limit. Short, precise comments beat long prose. If it gets tight, the “game version” in the IC10 coder helps.

Note

A define value may be a number, a constant or HASH("…") – but not another define name. The game silently stores NaN then.

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
The proven layout: define block with comments at the top, the alias block below, then the main loop with yield.

Exercise

Task

The code below works, but is barely readable. Restructure it without changing what it does:

  • The limit 303.15 gets a define with a comment.
  • Every register in use gets an alias.
  • The body contains no raw 303.15 and no bare r0/r1 any more.

Hints

Hint 1

define LIMIT 303.15 # 30 C at the very top.

Hint 2

Then alias temp r0 and alias hot r1 – and replace r0 with temp and r1 with hot in the body.

Hint 3

The pins may get an alias too: alias sensor d0.

Esc
↑ ↓ selectEnter open/ opens search anywhere