Skip to content

Arithmetic

Add, subtract, multiply, divide — and what to do when there are two operations

The op block has four fields: where to put the answer, what to do, and the two numbers it is done to. Numbers can be written straight into the fields or supplied as variables — the block does not care.

tick 0
Set0
=
Set1
=
Operation2
=
Operation3
=
Operation4
=
Operation5
=
@counter0number
anullnull
bnullnull
sumnullnull
differencenullnull
productnullnull
quotientnullnull

The first two lines put numbers into a and b, the other four compute. The variables window shows all four answers at once:

Operation In the block What it computes Answer with a = 12, b = 5
add + addition 17
sub - subtraction 7
mul * multiplication 60
div / division 2.4

Division is ordinary, not integer: 12 divided by 5 is 2.4, and the fractional part does not go anywhere. How to get a whole number and a remainder is in the lesson «Whole numbers and precision».

The familiar total = (a + b) * 2 does not exist in mlog. The instruction does exactly one thing, so an expression unfolds into a chain, with the intermediate answer put into a variable:

tick 0
Set0
=
Set1
=
Operation2
=
Operation3
=
@counter0number
anullnull
bnullnull
sumnullnull
totalnullnull

First sum becomes 17, then that same value goes into the multiplication — and total comes out as 34. The name sum is not special here but invented: an intermediate answer can be called anything.

Half the operations need no second argument at all, and the editor simply does not show it: choose abs and the second field disappears. That is how absolute value, square root, rounding and trigonometry work.

op abs answer -5 gives 5, op sqrt answer 81 gives nine. One field is left, because one number is all the work needs.

Operation In the block What it does Example
pow ^ raises to a power op pow answer 2 10 → 1024
max max takes the larger of two op max answer 3 7 → 7
min min takes the smaller op min answer 3 7 → 3

max and min are the usual way to keep a number inside bounds: max with the lower one first, then min with the upper, and the value is clamped between them.

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.