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

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

The limits in detail

The three limits in detail: what counts towards 128 lines, 90 characters per line and 4096 characters, why HASH counts in its long form and how to measure characters.

Lesson 16 min Week 44

What you learn today

  • What exactly counts
  • Preprocessor and long form
  • Measure characters

You have known the limits since day 5: 128 lines, 90 characters per line, 4096 characters in total. For small chips they do not matter. With the big plants of the last weeks you run into them – and then every detail of what exactly counts matters.

What exactly counts

Limitcounts
128 linesevery line: code, comment, blank line, label, define, alias
90 characters per lineeverything in the line, including the comment after it
4096 charactersthe whole text, including spaces, comments and line breaks

A line that has 95 characters with its comment is too long – even if the code alone only has 60. The chip then cannot be loaded.

Preprocessor and long form

The preprocessor replaces HASH("…"), STR("…"), %1010 and $FF with numbers when loading. But the counting happens before that, in the long form, as you wrote it:

writtencharactersafter the preprocessor
HASH("StructureHydroponicsTrayData")37-1841632400
HASH("Beet")12a number
%1111_111110255

A define therefore pays off from the second use: the line define TRAY HASH("StructureHydroponicsTrayData") costs about 50 characters once, every use after that saves 33.

lbns ripe HASH("StructureHydroponicsTrayData") HASH("Beet") 0 Mature Average
define TRAY HASH("StructureHydroponicsTrayData") # hydroponics device
lbns ripe TRAY HASH("Beet") 0 Mature Average

Measuring characters

The IC10 coder on this site shows lines and characters while you write and marks every line over 90 characters. In the game you only see it when the chip rejects the code. You can estimate like this:

  • A typical instruction line has 25 to 45 characters.
  • 128 lines of 32 characters each are already 4096 – with long comments you almost always reach the character limit before the line limit.
Warning

Every line counts with a line break. 100 blank lines are 100 characters and 100 of 128 lines – gaps between sections are not free.

Tip

Rather write comments above the line than after it. Then the instruction line stays short, and a long explanation does not blow the 90 characters.

Diagram

The three limits of a program Lines 74/128 Characters 3990/4096 Width 97/90 Comments and blank lines count fully. The longest line here is too wide.
What counts is the text as it stands in the editor – with comments, blank lines and HASH calls written out.

Exercise

Task

The starter code works but cannot be loaded: three lines are longer than 90 characters. Bring every line below 90 characters by moving the prefab hashes into defines and putting long comments above the line. The behaviour stays the same.

Hints

Hint 1

Create define TRAY HASH("StructureHydroponicsTrayData") and define DISP HASH("StructureConsoleLED5").

Hint 2

In the body use TRAY and DISP instead of the long HASH calls.

Hint 3

Move the comments behind the instructions one line up.

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