The variables window
The only place that tells the truth about what the program has computed
mlog has neither error messages nor crashes. A program with a typo does not complain — it silently computes the wrong thing. That makes the second most important button under the program window “Variables”: it shows the contents of the processor’s memory at this moment.
On the course pages that table is always open to the right of the lines: in an example you need to look at it more often than you do in the game.
What is in a row
Section titled “What is in a row”A row of the table is three cells: name, value, type. The game names the type in its own word and paints it in its own colour:
| Type | What it is |
|---|---|
number |
a number |
null |
empty: the variable was never written to |
string |
text in quotes |
content |
an item, a liquid, a block or a unit type |
building |
a building — the thing a link gives you |
unit |
a unit |
team |
a team |
enum |
a value from a list, like enabled |
The table usually starts with @counter — the number of the line that will run next. Then
your variables, in the order they first appeared in the program.
Not everything is visible
Section titled “Not everything is visible”Constants do not make it into the table: @copper, @this, @ipt, @links and link names
(cell1, switch1) will not show up there — they do not change, so there is nothing to show.
Their list opens with the “Built-in variables” button in the same window; here it lives on the built-in variables page.
A typo is visible at once
Section titled “A typo is visible at once”The example below is the program from the previous lessons, but with one letter out of place:
the second line says stok, not stock. Press “run” and look at the table.
total is five instead of twenty-five. Why, is visible in the same place:
stokis an extra row with the valuenull. For a name that was never assigned, mlog creates a variable of its own and putsnullin it. An unfamiliar name is not an error to it, but a new variable.doubledis zero. In arithmeticnullcounts as zero: zero times two is zero.totalis five. Zero plus five. The program ran honestly, just with the wrong number.
This is the most common way to break a program, and it is cured with your eyes: two nearly identical rows in the table mean you made a typo.
Values do not refresh instantly
Section titled “Values do not refresh instantly”In the game the table re-reads its values once every fifteen ticks — about four times a second — and a changed number flashes yellow. That is not a delay in the counting but the rate of display: in that time the processor makes hundreds of steps, and you cannot see each one.
While the variables window is open the game is not paused: the program window pauses it and the variables window unpauses it — otherwise the numbers would not change.
In the course examples the table refreshes every frame, and the “step” button lets you look at exactly one instruction — the game cannot do that.
Harder debugging is in the lesson “When it does not work”.
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.