The text buffer
The string is assembled piece by piece and sits inside the processor until it is handed out
Every processor has a text buffer — a string that print appends values to, one after
another. While it is inside, nobody sees it: not the player, not the neighbouring blocks.
Press “step” five times and watch the bottom row of the table: the buffer fills up with
copper: 120 of 300. Four prints — four pieces, glued together in the order the lines ran.
The language has no string concatenation
Section titled “The language has no string concatenation”The familiar "copper: " + copper does not exist in mlog: op add with a string gives
a number, not a string. Only the buffer can join text, and it does so in exactly one way —
one piece per instruction.
Hence the usual shape of such a program:
print "copper: "print copperprint " of "print 300Four lines for one line of text is normal. When there are many pieces,
format comes to the rescue: it substitutes values into
a ready template.
The buffer is not endless
Section titled “The buffer is not endless”It holds 400 characters. Everything that does not fit is simply not appended: there is no error and no warning — the end of the line is just cut off.
Four hundred characters is a lot for a caption and not much for a report. Printing in a loop overflows the buffer unnoticed, and the display or the block shows exactly the first part.
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.