Skip to content

Number, object and text

A variable holds either a number or an object — and what you can do with it follows from that

easy

An mlog variable holds either a number or an object. Everything that is not a number is an object: a string, an item, a block, a unit, a team. Emptiness, null, is a kind of object all its own, and it gets a lesson of its own.

tick 0
Set0
=
Set1
=
Set2
=
Set3
=
@counter0number
numbernullnull
textnullnull
itemnullnull
unsetnullnull

To the right of the value the table shows the kind: number, string, content, null. It is the same column the “Variables” window shows in the game itself, in the same colours.

A variable does not hold a kind by itself. Write a number into it and it is a number; write @copper and it is an object. The same variable is both at different points in a program’s life, and nobody complains.

There is nowhere and no need to declare a kind in advance: mlog has neither types in a declaration nor a check on assignment. The only place the kind is visible is the variables table.

Numbers count as numbers. But when an object lands in arithmetic, the game does not work out what it is:

  • op add two @copper 1 gives 2, because copper as a number is a one;
  • the same happens with any building, unit or string;
  • and only null gives zero — that is the next lesson.

The rule is simple: any object in a numeric context equals one, emptiness equals zero. This is not a “type conversion” but a rule, and there is no other way to get a number out of an object.

"copper" is a string: print, format and comparisons work with it, arithmetic does not. You can add a string to a number, only the result will not be what you expect: the string goes into the sum as an object, that is, as a one.

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.