Skip to content

Course

The course is split by what you are doing: the language, the logic processor, the world processor, and the techniques on top. Inside are the same categories and groups the game itself uses: a group is an instruction, a lesson is one facet of it. Groups are independent — go straight to the unit ones; each says up front what you need to know first.

easy
Reads from scratch: nothing needs to be known first
medium
Needs other lessons, listed at the top of the page
hard
The fine print: a program that looks right lies silently. Read it once the basics have settled

Basics

The things that aren't about an instruction, but without which none of them read

  1. Writing it in the gameWhere the program lives, what a line is made of and what the buttons around it do
  2. A program is textAssembled from blocks, stored as lines — and that is worth using
  3. The variables windowThe only place that tells the truth about what the program has computed
  4. How the processor worksThe program runs top to bottom and starts over. Lines count from zero, speed is measured in instructions per tick
  5. Number, object and textA variable holds either a number or an object — and what you can do with it follows from that
  6. Emptiness: nullThere is no value — and that is a value too. The main source of silent mistakes in mlog
  7. Variables and namesA variable isn't declared — it's just named. Which names are free, and which are already taken
  8. Links and getlinkA link is not adjacency: a block has to be connected, and only then does it get a name
  9. When it does not workmlog reports no errors. So you have to look yourself — and there is an order in which it is done

Logic processor

Input & Output

Read

One instruction and three different correspondents: a memory cell, someone else's processor and an ordinary string

  1. The memory cellA processor's memory dies with every edit to the program. A cell remembers — and you fetch from it by slot number
  2. Another processor's variablesA cell for exchanging values isn't always needed: a neighbour's variable can be taken straight from it, by name
  3. A character from a stringA string is read by address too: a character index instead of a slot number, a character code instead of a value

Write

Variables live between iterations, but they don't survive an edit to the program. Memory does

  1. Writing to a cellOne line, three fields — and the value survives the iteration, the edit and the processor itself
  2. An object in a cellA cell stopped being an array of numbers. You put an item, a store or a unit in — and get the same thing out
  3. Shared memoryA neighbour's variables are visible to nobody. A cell is visible to everyone linked to it — and that is what division of labour is built on
  4. A neighbour's variablesA cell for exchanging values isn't always needed — but the shortcut is paid for with a variable that changes with no trace in the program

Draw

draw draws nothing. It piles commands up in the processor's buffer, and another instruction shows them to the display

  1. The first pictureFour lines and a rectangle appears on the display. Without the last of them nothing appears at all
  2. Shapes and linesThere are six shapes, and each asks for its own numbers: a corner here, a centre there, a radius elsewhere
  3. Colour and transparencyColour is a state, not a property of a shape: choose it once and it holds until the next time
  4. Text and picturesText reaches a display from the same buffer that feeds a message block — but not every letter survives the trip
  5. Translate, rotate, scaleEasier than recomputing every point: move the grid itself and draw in it as if for the first time

Print

Text in mlog isn't shown, it's accumulated: print writes into a buffer, and another instruction shows it

  1. The text bufferThe string is assembled piece by piece and sits inside the processor until it is handed out
  2. What prints as whatAnything can be printed — and almost everything turns into text differently from what you expect

Print Char

One character at a time — but any of them: an arrow, a box-drawing line or the copper icon

    Format

    A whole template instead of text in pieces: format drops values into a ready caption

      Block Control

      Draw Flush

      A processor's command buffer is not endless: 256 at a time, and everything above that is lost in silence

        Print Flush

        Accumulated text is shown not by print but by printflush — and it clears the buffer whatever happens

          Links have an order, and you can walk it — without knowing in advance what is connected

            Control

            sensor asks, control orders. Only the blocks the processor is linked to obey

            1. Switching on and offThe one command that works on any block: switch it off and switch it back on
            2. Configuring a blockA sorter, an unloader and a factory are configured with an item — and logic can change that setting on the fly
            3. ShootingA turret shoots well enough on its own. Logic is for when it matters who exactly it shoots

            Radar

            How a block learns that somebody is nearby: units only, within its own range only, and only the best one

            1. Finding a unitThree conditions are joined by a logical AND, and the range is taken from the block you look from
            2. Sorting and the cacheA radar answers not «who is there» but «who is best». And it does not answer afresh every time

            Sensor

            How a processor learns what is happening around it: how much copper is in the vault, where a unit is, whether a block is intact

            1. Properties of buildingsAsk a linked block for a number — how much is inside, how much fits, whether it is intact
            2. Items and an empty answerHow much copper is in a block — and how "there is none of it" differs from "the question does not apply"
            3. Properties of unitsAfter ubind you can ask @unit the same things — where it is, whether it is intact, what it is busy with
            4. Not everyone has every propertyWhy only a turret has @ammo and only a drill has @progress, and how a block's type differs from a building

            Operations

            Set

            The simplest instruction in the language: take a value and put it into a variable

            1. Assignment and copyingPut down a number, a text or another variable's contents — and how a copy differs from the original
            2. Content constantsAn item, a liquid, a block and a unit are values like a number: they go into variables and get passed to instructions

            Operation

            Everything the processor can compute: from addition to sine and noise

            1. ArithmeticAdd, subtract, multiply, divide — and what to do when there are two operations
            2. Whole numbers and precisionHow to get a whole number and a remainder, and what to expect from fractions
            3. Comparisons and logicA comparison is a number too, and it can be worked with like one
            4. Bitwise operationsA number as a set of bits: masks, shifts, and why shifting by 64 changes nothing
            5. Angles and distancesThe distance to a point, the angle to it and the difference between two angles — three operations everybody needs
            6. Randomness and noiseTwo operations about unpredictability: one different every time, the other smooth

            Select

            Pick one value out of two by a condition, without sending execution off to the side

            1. Choosing a value without a branchA branch for the sake of one value is unnecessary — but select is not always needed either: a comparison already has an answer

            Lookup

            All the game's content is numbered. Lookup turns a number into an object — and opens up walking the whole list

              Pack Color

              A colour made of four numbers is awkward to carry around. packcolor folds it into one — and the colour becomes an ordinary value

                Unpack Color

                The other side of packcolor: one number becomes four again

                  Flow Control

                  Wait

                  A program spins sixty times a second even when it need not. wait is the way to stop doing that

                  1. A pause in secondsWait this many seconds — and spend not a single instruction on the waiting
                  2. A program's rhythmSixty iterations a second are rarely needed. How to choose a rhythm and how to set it

                  Stop

                  Not a pause but the end of work: after stop the processor runs nothing

                    End

                    Start the iteration over — and, against expectations, without giving up the tick

                      Jump

                      Check a condition and go somewhere other than you normally would: branches and loops

                      1. Condition and branchingOne check — two roads. How a program stops being a straight line
                      2. LoopsThe same jump, only the arrow points up — and the program starts repeating a piece of itself
                      3. Nested conditions and early exitA jump has one condition and one target. Everything else — «and», «or», else, leaving a loop — is assembled out of several jumps

                      Set Rate

                      A processor always runs at its own speed. setrate is the only way to change it, and it is almost always changed downwards

                        Unit Control

                        Unit Bind

                        A processor does not drive units in general. It drives one — whichever is bound right now

                        1. Binding by typeOne ubind, one unit. The next one gives another, and so on round the circle until they run out
                        2. Keeping one unitThere is no point binding every iteration. A proper loop binds rarely — only when the previous unit will no longer do
                        3. Other teams' unitsAn enemy unit cannot be driven — neither by type nor by object. Looking at it is free

                        Unit Control

                        Everything a unit can do on command is done by one instruction with different first fields

                        1. Movement and stoppingCoordinates in tiles, an order that lasts ten seconds, and «stop» that does not mean «freeze»
                        2. Arrival: withinA unit will never stand exactly on a point. The question to ask is not «is it there» but «is it close»
                        3. Items: take and dropA unit is a portable storage slot: one kind of item, a few places and a compulsory delay between trips
                        4. The flag as a tagEvery unit has a number the game never uses. Without it two processors will pull one squad apart
                        5. MiningNot everyone mines and not everything is minable, and they mine from where they stand — reaching the tile is the unit's own problem
                        6. Who is driving the unitA unit obeys whoever commanded it last. Two properties tell you who that is right now

                        Unit Radar

                        The same radar, only it looks from your unit rather than from a building — and with your unit's range

                          Unit Locate

                          A radar looks for units; ulocate looks for places: a tile with ore, the nearest enemy turret, a damaged building of yours

                          1. Where the ore isOre coordinates are not written out by hand: everybody's map is different, and the search is one line
                          2. Buildings by flagA building cannot be searched for by type, but it can be searched for by role: core, turret, store, generator
                          3. Damaged buildings and checking the findThe fourth kind of search looks for what needs repairing. And on the way, why the answer sometimes sticks

                          World processor

                          What a world processor is

                          The same language, the same blocks — but it can change the map itself, and it cannot be built in an ordinary game

                            Query

                            A radar gives you one. Query gives you everybody who fell inside a circle or a rectangle

                              Get Block

                              A tile has not one content but four layers. getblock asks about any of them

                                Set Block

                                Editing the map on the fly: a block appears instantly, with no construction, no resources and no queue

                                  Spawn Unit

                                  A unit appears whole and at once — with no factory, no resources and no queue

                                    Spawn Bullet

                                    A shot with no shooter: the bullet is borrowed from a turret and flies from wherever you say

                                      Apply Status

                                      Burning, freezing, boosted, immobilised — all of it is one instruction with two modes

                                        Weather Sense

                                        Is it raining, snowing or storming right now — a binary answer and nothing beyond it

                                          Weather Set

                                          Weather on a map is not chance but a state a script can control

                                            Spawn Wave

                                            A wave on schedule is the game's business. A world processor can call one early or drop it somewhere else

                                              Set Rule

                                              What a map's author normally sets in the settings, a world processor changes during play

                                                Flush Message

                                                The same print buffer, only it goes not to a message block but straight to the player's screen

                                                  Cutscene

                                                  The only instruction that talks not to the map but to the player's screen

                                                    Effect

                                                    Three dozen ready-made effects from the game: an explosion, smoke, sparks, a trail. Pretty and entirely harmless

                                                      Explosion

                                                      Damage with no source: no turret, no bullet — something simply exploded at a point on the map

                                                        Fetch

                                                        A radar sees around itself, query sees an area. Fetch sees everything a team has on the map

                                                          Sync

                                                          In a single-player game it does nothing. On a server it is the only way to show everybody the same number

                                                            Client Data

                                                            A message not to the screen but into the client's program: a channel, a value and a choice between «reliable» and «fast»

                                                              Get Flag

                                                              The other side of setflag — and the only way to learn that something happened somewhere on the map

                                                                Set Flag

                                                                Shared memory for the whole map: not a number and not an object, just a «yes» under a name

                                                                  Set Prop

                                                                  The other side of sensor: what it reads, setprop writes — bypassing all physics

                                                                    Play Sound

                                                                    A sound from a point on the map or straight into the player's ears — with every knob the engine has

                                                                      Play Music

                                                                      The simplest instruction in the whole part: a tune's name and one flag

                                                                        Set Marker

                                                                        One instruction for every property of every marker: whatever this kind understands is what changes

                                                                          Make Marker

                                                                          A drawing over the map that the player sees: a circle over a point, a caption, an arrow, a line

                                                                            Locale Print

                                                                            The same print, only the text comes from the map's dictionary rather than from the program — a different one per language

                                                                              Advanced

                                                                              The things that are not about one instruction but about how a working program is assembled from them

                                                                              1. @counter: a jump as a valueA jump is not only jump. The number of the next line sits in a variable, and it can be calculated
                                                                              2. Inside a numberThere is one number type in mlog — double precision. Hence both the 53-bit limit and 0.1 + 0.2 ≠ 0.3
                                                                              3. Labels instead of line numbersA line number in a jump is a choice, not an obligation. In the text form the target can be called by name
                                                                              4. Time: @time, @tick, @secondTick, second, minute and millisecond — one and the same time in four forms. Which one you pick depends on the task
                                                                              5. What an instruction costsA processor has no «expensive» and «cheap» lines: it counts them by the piece, and the pieces per tick are exactly @ipt
                                                                              6. Packing dataThere are few slots in memory, and a unit has exactly one flag. Several numbers have to be folded into one
                                                                              7. Several processorsOne processor is one queue of lines. Two run in parallel — and that is the only way to speed up without changing the block
                                                                              8. Limits and the game's editorA thousand instructions, four hundred buffer characters, 256 draw commands — limits are worth knowing before you hit them
                                                                              9. The fine printA collection of places where intuition fails: comparisons with a tolerance, null instead of infinity and objects equal only to themselves

                                                                              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.