Skip to content

A high level language for Mindustry Logic (mlog) and Mindustry Schematics.

License

Notifications You must be signed in to change notification settings

cardillan/mindcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mindcode: a high-level compiler for mlog


Static Badge Static Badge Static Badge GitHub issue custom search in repo Static Badge


Mindcode is a high-level programming language for Mindustry Logic. Many language features are provided, including variable declaration, arrays (including @counter arrays), conditional statements and loops, functions, modules, remote function calls, system library etc. Mindcode generates fairly well optimized mlog code, utilizing available instruction space to make the resulting code faster. It comes with a web app and a command-line compiler, provides means for integration both with various IDEs and Mindustry itself.

Schemacode, an extension built over Mindcode, is a specialized definition language designed for creating a complete Mindustry schematic from a text file. Schematics builder compiles these definition files directly into Mindustry schematics, either into binary .msch file, or into the text representation. Processors can be included in these schematics, complete with the code (specified either in Mindcode or mlog) and linked blocks.

Note

To use new Mindustry Logic capabilities from the new Mindustry 8 pre-release, use #set target = 8; in your code. Here is a summary of the new Logic content and corresponding Mindcode functionality.

Mindcode Syntax

Please refer to the documentation for a complete description of Mindcode syntax. You can also use the code examples in the web application to get familiar with Mindcode.

You can also visit golem, a collection of more complex Mindcode and Schemacode scripts.

Latest development

See issues for open bugs and possible workarounds.

The most important recent changes to Mindcode include:

  • Language features
    • Passing arguments (including arrays) to inline functions by reference.
    • Specific syntax for mlog keywords.
    • Support for passing mlog keywords as arguments to inline functions.
    • External and internal arrays (@counter arrays), including basic array optimizations.
    • Expressions in string interpolation: print($"Sum: ${a + b}.").
    • Support for color literals: %00ffff80.
    • Prefix/postfix increment/decrement operators: i++, --j.
    • Redefined strict and relaxed syntax modes.
    • Variable declaration (optional in relaxed syntax, compulsory in strict syntax).
  • Basic functionality
  • Mindustry Logic 8

See changelog for a comprehensive list of changes.

Using Mindcode

Online

Mindcode is available at http://mindcode.herokuapp.com/. Write some Mindcode in the Mindcode Source Code text area, then press the Compile button. The Mindustry Logic text area will contain the mlog version of your Mindcode. Copy the mlog code into the clipboard. Back in Mindustry, edit your processor, then use the Edit button in the Logic UI. Select Import from Clipboard. Mindustry is now ready to execute your code.

You can also use the Compile and Run button to execute the compiled code right away on an emulated processor. The output produced by print instructions in your code will be displayed. Very limited interaction with the Mindustry World is supported.

Tip

Mindcode performs a variety of different optimizations. The mlog code it produces may bear little resemblance to the original source code at a first glance.

Offline

Alternatively, you can download the command-line compiler and use Mindcode from within an IDE.

Support mods

Mindcode can interface with the Mlog Watcher mod to inject the compiled code into selected processor in Mindustry World directly, witthout having to use a clipboard.

The Mlog Assertions mod, available for Mindustry 7, allows efficient array-bounds checking for both internal and external arrays, making this kind of bugs easier to detect.

Mindustry Logic References

If you don't know much about Mindustry Logic, you can read more information about it here:

You can also get help on these Discord servers:

Roadmap

An overview of planned new functionalities is available here.

Actual progress of development is published in the #development channel on Discord.

Comments and ideas are welcome at both places.

Contributing

See CONTRIBUTING.

License

MIT. See LICENSE for the full text of the license.