Skip to content

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.

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.

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.

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.

tick 0
Set0
=
Operation1
=
Operation2
=
@counter0number
stocknullnull
doublednullnull
stoknullnull
totalnullnull

total is five instead of twenty-five. Why, is visible in the same place:

  • stok is an extra row with the value null. For a name that was never assigned, mlog creates a variable of its own and puts null in it. An unfamiliar name is not an error to it, but a new variable.
  • doubled is zero. In arithmetic null counts as zero: zero times two is zero.
  • total is 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.

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.