Skip to content

Assignment and copying

Put down a number, a text or another variable's contents — and how a copy differs from the original

set is the first instruction almost every program puts down: before anything can be computed, the starting numbers have to come from somewhere.

Press “step” four times and watch the table.

tick 0
Set0
=
Set1
=
Set2
=
Set3
=
@counter0number
stocknullnull
textnullnull
copynullnull

A number is written as it is: 5, -0.25, 1e6. A point, not a comma; the minus sign sits against the number.

Text goes in double quotes: "copper". In the variables table its type is string, and not every instruction works with it: text cannot be added to a number, but it can be printed.

A taken name@copper, @this, @time. These are the game’s constants, and they are the next lesson.

Another variable — then the value is copied. More on that below.

The example’s third line is set copy stock, and at that moment stock holds a five. The fourth changes stock to 99, and copy stays a five.

That is the main rule: the value is copied, not a link. mlog has no “reference to a variable” and no way to say “let this variable always equal that one”. Every set line is a one-off action: take what is on the right now and put it on the left.

A value is not always a number. If a variable holds a building or an item, that is what gets copied: set other container1 puts that very same container into other.

It does not make a copy of the container — there is one container, it is just that two variables now look at it. As with a number, copying is a one-off: demolish the container and both variables keep a building that no longer exists.

  • Compute. set total stock + 1 cannot be written: addition is op.
  • Write into taken names. set @copper 7 does nothing. The one exception is @counter, where writing means a jump.
  • Declare a variable in advance. mlog has no “declare a variable” line: a variable appears from its first mention, and set is simply the first place that usually happens.

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.