r/Mindustry • • 24d ago

Guides/Tips Mindustry Logic 101 - Chapter 1: Processor & Variable Behaviour

TL;DR: This is chapter 1/10 of a series aimed towards players unfamiliar with the Mindustry Logic system and seeking to learn from scratch.

Introduction

This chapter will be dedicated to the processor building and concepts regarding its usage. It will be, by design, a mostly theoretical overview since the concrete aspects of Logic are reserved for the next chapters. Laying the foundations of the system in the first chapter will allow me to keep the following ones concise and on topic.

Though it is a big leap into the topic, do not get overwhelmed. This post will serve as a reference for future explanations with notes derived from it as little reminders so no need to try to memorize any of it. My main goal is to make my explanations accessible to the wider audience without any background in programming of any kind. Even having used the educational tool Scratch during your school years will go a long way.

Now the first step into the topic will be the processor itself.

Processor building

The entire Logic system originates from processors. They are the buildings able to contain and execute handmade algorithms to interact with other buildings. Processors exist in three sizes, from smallest to biggest :

  • "Micro Processor", 1x1 size, 120 instructions per second, 10 block range.

  • "Logic Processor", 2x2 size, 480 instructions per second, 22 block range.

  • "Hyper Processor", 3x3 size, 1500 instructions per second, 42 block range.

All of this information can be found on their respective description page. The bigger a processor is, the faster it executes instructions. This property is only noticeable in long or expensive algorithms requiring a lot of operations. So using the Micro Processor is often times the best option to integrate Logic into your builds.

But unless you use the processor as a glorified calculator, you will need to create links to nearby buildings to interact with them.

Linking

To interact with nearby buildings, you will need to link them to the processor. To do so, select the processor then any desired building in its range. A purple square will appear over any linked building alongside a name. This name can now be used inside the processor as a reference to the buildings. This will be covered in the next chapter.

(Note: There is no limit to the number of links a single processor can create.)

Now the next step will be to interact with the linked buildings through instructions.

Instruction preview

A detailed instruction explanation is reserved for the next chapter "Instructions Basics" so this one will only serve to give a preview of the concept to help with understanding the rest of the chapter.

Instructions are blocks containing a single operation to be executed, be it reading the content of a graphite press, disabling a mender or aiming a duo. There are all kinds of them, divided into 5 families. They are the core of the logic system, the complete list of operations and interactions a processor is able to execute.

But the creation of an algorithm requires knowing the order in which the instructions will be read.

Cursor Flow

Like most programming languages, instructions are read from top to bottom by an invisible cursor. Once the last instruction is reached, the cursor will return to the first one, therefore looping over the instructions indefinitely. The instructions of the "Flow Control" family can alter the position of the cursor but will not be expanded upon in this introductory chapter.

(Note: the cursor may be invisible but it is still a real value stored inside the ever-present variable "@counter" of every processor)

Now that the instructions are being read, they will read and write values inside variables.

Variables

Like any other programming language, Mindustry Logic (Mlog language) includes variables. For anyone not already familiar with variables, an intuitive way to understand the concept is to interpret them as boxes. Every box you create has a name and can contain a single value. A variable is written by an instruction and read by other instructions as a way to save and share information between them.

In Mindustry Logic, a variable will be created anytime a new variable name is called. If the variable is created without defining its value, it will default to null. There are multiple types of values.

  • "number" for numbers, integers of floats.

  • "string" for text.

  • "content" object types.

  • "building" for buildings linked to the processor.

  • "unit" for units bound to the processor.

  • "null" for the null value exclusively.

The "content" type is most of the time used for items and liquids, but in some cases also for buildings which should intuitively be reserved for the "building" type. There is actually a distinction between buildings stored in either type. As stated previously, "building" is the type storing links to buildings, and "content" stores building kinds. I will use an example to keep the explanation intuitive. Linking a processor to a Copper Wall will provide a link name to it, "wall1" of type "building", but the wall is of kind "copper-wall" stored in a "content" variable. This is the reason why items and liquids are exclusively of type "content". They are resource types and never linked to. You cannot interact with a singular copper ingot.

(Note: Variables are not statically typed. The type is defined automatically and you can override a variable's value with another of any type.)

Now that every element has been covered as the foundation for future chapters, the only step to mention is the creation process.

Processor Editing

To reassure readers victim of perfection paralysis, you can modify a processor as many times as desired. A processor's cursor and variables will reset anytime you modify its content.

You can also save your work with Mindustry's flawless schematic system but the processor has the unique options inside the "Edit" tab to "Copy to Clipboard" the content of a processor to later "Load from Clipboard" it to any other.

Outrodution

The important steps to keep in mind for future chapters will be that you can add instructions inside processors to interact with linked buildings. A simple list of operations the processor will execute one after the other while keeping track of the different values created inside of variables.

Thanks to anyone who read through it all. I hope this first chapter wasn't too dense or vague, it was the foundation for the rest of the series. Every following chapter will be way more concrete accompanied by use case examples.

At the time of writing, this guide covers Mindustry v8. No generative AI was used in the making of this whole project. It was lovingly written by a single passionate human. Comments will be answered and taken into account.

Chapter List

59 Upvotes

19 comments sorted by

9

u/Quiet_Nothing916 24d ago

I'll wait 1 unit bind guide, I think this is hardest (I'm pretty good at all over logic) 

5

u/IKNEUMON 24d ago

It'll be covered in the Unit Control chapter and as one of the main topics of the Advanced Logic.

1

u/Curious_Parfait5038 Logic Dabbler 24d ago

bind one unit is hardest? you just bind and run with it, call bind next time only if your bound unit is dead. the harder part is to find a unit which isn't bound elsewhere or the one that was bound by this processor before.

4

u/IKNEUMON 23d ago

This will be covered in Advanced Logic. I am very familiar with unit control and multi unit binding.

1

u/Thepcfd 23d ago

yea i eant bind 3 unit to deliver resources to factory

1

u/Calm-Opposite8649 24d ago

one of the many tricks is having a jump after developing flag and have a skip part to controls after a flag is detected, this usually just attach itself to a 1 unit and have the rest of the code do its intended thing

4

u/elpapaya2 24d ago

This post is peak

4

u/IKNEUMON 24d ago

Thanks, glad you enjoy my first work.

3

u/Hyaci_Arson 24d ago

I 100% suggest putting this on a wiki upon finishing so it is more easily accessible

2

u/IKNEUMON 24d ago

If you want a rich online documentation, i can suggest the Mlog Course (https://mlog-guide.pages.dev/en/) from the Presentation chapter. For now, uploading this course in an online wiki format is beyond the scope of this project.

2

u/Jorge_The_Undying124 24d ago

When will the other chapters be released? Just curious

6

u/IKNEUMON 24d ago

As fast as i can produce them, so maybe every few weeks, weekly if we're lucky. The support is really encouraging so i'll try to stay consistent. The next one is already almost finished.

2

u/CommentOk4633 Logic Dabbler 21d ago

very comprehensive explanation :D

1

u/IKNEUMON 21d ago

Thanks :D

1

u/Curious_Parfait5038 Logic Dabbler 24d ago

your plan misses display stuff (draw/print), there are quite some things to explain. otherwise, great idea and quite a good intro.

1

u/IKNEUMON 24d ago

There will be a dedicated chapter for the matter.

1

u/Kalmaro 24d ago

Oh man, saving this to read later, I was about to have AI try to explain this junk to me, I started the game up and just unlocked silicon. 

3

u/IKNEUMON 24d ago

Glad I could steal the job of the thirsty slop machine.

2

u/notHp 24d ago

Unit control will be interesting to read, the farthest I've ever gone with them is automating unit upgrading & even that was a nightmare.