A character from a string
A string is read by address too: a character index instead of a slot number, a character code instead of a value
The third thing read can read is an ordinary string. The address here is a character index,
and the answer is its code, a number:
read code "mlog" 0code gets 109 — that is m. Not a letter, a number: mlog has no separate “character” kind
at all.
The program walks the string character by character and puts them back together with
printchar. The board shows mlog — the same string, only assembled one character at a time.
Why, if a string cannot even be joined
Section titled “Why, if a string cannot even be joined”Strings in mlog are almost immovable: they cannot be concatenated, compared or trimmed. The only things you can do with one are print it whole and take it apart character by character. Hence the uses:
- print text letter by letter — a crawling line on a board, a letter per iteration;
- break a string into codes and store them in memory, to reassemble them in another order later;
- fetch a single character out of a prepared set:
read code "0123456789" digitturns a number into the code of its digit.
The bounds are the same as memory’s
Section titled “The bounds are the same as memory’s”| Address | What happens |
|---|---|
0 … length minus one |
the character’s code |
| length and above | emptiness |
| negative | emptiness |
| fractional | truncated: 2.9 is character 2 |
There is no way to find out a string’s length — the language has no “how many characters” instruction. So a loop over a string either knows the length in advance or runs until the first emptiness:
read code "mlog" indexjump 5 strictEqual code nullprintchar codeop add index index 1jump 0 alwaysprintflush message1Unofficial 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.