Skip to content

Labels instead of line numbers

A line number in a jump is a choice, not an obligation. In the text form the target can be called by name

mediumYou need: Loops, Writing in the game
tick 0
Set0
=
Operation1
=
Jump -> 12
if
Set3
=
Stop4
@counter0number
countnullnull
readynullnull
set count 0
again:
op add count count 1
jump again lessThan count 5
set ready 1

The line again: is a label. It is not an instruction: it costs no line number, the processor does not execute it, and jump again leads to the line right after it.

The game itself parses such a program: labels are understood by its text parsing, not by some external editor. Copy the example into the “Edit code” window — it will work.

What How it is written
declaring a label a single word ending in a colon: again:
jumping to it the name instead of a number: jump again always

The rules are simple:

  • a label takes up the whole line; nothing else may be on it;
  • the name can be anything, Cyrillic included;
  • two labels with the same name are a parse error, not a silent substitution;
  • a jump to a label that does not exist is an error too, and the game will say so.

A line number is a fragile reference. Insert a line in the middle of a program and every jump below points to the wrong place — silently: the program keeps running, just incorrectly.

A label is tied to a place, not to a number. And it reads: jump checkStock says what is meant, while jump 17 says only which line.

  • long programs written in an outside editor and pasted in whole;
  • programs assembled by something else — a compiler targeting mlog, say: there labels are the only sensible way to refer to a place;
  • portable pieces: a piece with labels can be pasted into the middle of somebody else’s program and nothing shifts.

Unofficial fan project, not affiliated with Anuke. Mindustry sprites, fonts and translations © Anuke, used under GPL-3.0; Fira Code under OFL-1.1. Site code is GPL-3.0.