A mod formerly known as Mlog Assertions.
Note
Using this mod on maps with lots of processors may impact the game's performance.
This mod aims to make debugging in Mindustry Logic a bit easier. Provided functionality:
- Enhanced Vars screen: showing numeric values in full precision and color values, sorting variables by name, copying variables and the text buffer contents to the clipboard.
- Memory screen for inspecting contents of memory blocks, using the same interface as the Vars screen. Includes a command to clear (reset) the contents of memory blocks.
- Settings for overriding instruction limit, by up to 1000 instructions. This allows you to insert debugging code (e.g., additional
printinstructions) into your code, even if the original instruction limit is exceeded. - Snapshots allow saving, reviewing and restoring the state of logic processors, memory blocks and all other blocks on the map. A snapshot can be created manually or using a logic instruction. A limited number of snapshots is kept for each block, allowing to review the exact block state at the time the snapshot has been created.
- A profiler for gathering statistics about individual processor instructions execution.
- Logging: a custom
loginstruction creates logging messages that can be later inspected from the UI. - Custom mlog instructions for performing runtime checks, logging messages, reporting errors, triggering a breakpoint, taking snapshots and managing profiling.
- Visual indication of stopped processors, processors executing a
waitinstruction, and failed runtime checks, directly on the map. - Detection of silent parse errors: when processors stored in map files or schematics have errors in them, the errors aren't reported when the map is loaded or the schematic is built. The mod alerts you to these errors.
Note
No data generated by this mod, such as profiling data, in-game log messages or snapshot, are saved with the map. When the map is closed, all data generated by this mod are lost.
The Vars screen has been enhanced:
- Additional processor variables (the contents of the text buffer, current wait time,
@unit,@ipt) are included. - Numeric values are displayed in configurable precision. Integer values are clearly distinguished from decimal ones.
- Numeric values in the color range are formatted as color literals (e.g.,
%e55454ff), the color itself is presented using a glyph. - String values no longer cause overflow and are correctly rendered, including the color tags.
- Option to choose between formatting the numbers in hexadecimal or decimal base (including memory cell addresses).
- Option to sort variables by name or revert to their original order.
- Option to hide temporary variables and processor links.
- Commands to copy the variable list or the contents of the text buffer to the clipboard (in previous versions of this mod, these buttons have been included directly on the processor screen) or to write it into a file.
By tapping a memory block, a configuration menu is now displayed. The button opens a Memory screen, similar to the Vars screen described above. All options relevant to the specifics of memory blocks are available. Furthermore, the Edit button allows you to clear the contents of memory blocks, export them to the clipboard or a file, and import them back.
The exported data may be modified (for example in a spreadsheet) and imported back into the memory block. The columns of the table are separated by tabs, and the address of a cell is always given in decimal. Strings are written as literals enclosed in quotes, with the characters which would either be lost or break the table encoded using escape sequences (\n, \", \\, \uXXXX). Numbers may be entered in the decimal, color, hexadecimal or binary form, and values which are not finite are written and imported as null, as they are not representable in memory blocks. Lines which cannot be parsed are reported and skipped, and the memory block is only changed once the whole table has been parsed. Values having no representation in the text form (references to units, buildings and contents) are exported as well, but cannot be restored.
By triple-tapping any block, the Properties screen is displayed. The screen contains a list of all properties of the block in real-time in a format similar to the Vars/Memory screens.
By activating a profiler, it is possible to get execution statistics for the processor, i.e. the number of times each instruction has been executed. The profiling data are displayed on the Profiler screen available from the Vars screen. When the processor is running, the profiling data are updated in real-time. They can also be copied to the clipboard for later analysis. Profiling can be started and stopped from the Profiler screen, using the profile instruction, or using a custom game rule.
Profiling a program allows you to identify the instructions the processor has spent the most time executing. Profiling is relatively low-cost (at least compared to the snapshotting), and can be safely left active on many processors for long periods of time.
The profiler is stopped when the stop instruction is executed. A stop instruction usually indicates the processor's job is done, or an error has been encountered. Sometimes a schematic may use stop to temporarily pause processing, using other processors to resume execution. In such cases, it is possible to prevent the profiler from stopping on stop instruction in settings.
A message can be added to an in-game log using the log instruction. Logged messages can be inspected on the Log screen, including logs from processors connected to the current one via links or variables. The log content can be copied to the clipboard or saved to a file. Basic filtering by level and category is available. Logged messages aren't saved in the map file and are lost when exiting the map.
The maximum number of logged messages per processor is configurable in settings. When the limit is reached, older messages are removed from the log.
On the log screen, all filtering buttons are initially unchecked, which deactivates the filter. When at least one level or category button is selected, only messages matching selected levels and categories are displayed.
The log screen also includes buttons to switch between a live and paused/suspended mode:
- Live mode: the logs are updated and displayed on the fly. At most 100 of the latest messages matching the current filter are displayed, for performance reasons. Still, if the logic generates a lot of messages, the performance on some devices may suffer.
- Paused mode: the game is paused, meaning no new logs are generated. At most 5,000 messages matching the current filter are displayed.
- Suspended mode: the game is multiplayer and cannot be paused, but log updates are suspended. At most 5,000 messages from the connected processors are gathered, and the ones matching the filter are displayed. The set of log messages is stable and preserved until the Live mode is activated again.
Even when displaying logs from multiple processors, the log messages are always shown in the order in which they were generated.
A snapshot captures the state of a processor (all its variables), memory block (all cells) or a general block (all sensable properties). The mod allows creating and viewing snapshots.
There are several types of snapshots:
- isolated: keep a state of just a single block. Can be created using the
snapshotinstruction. - connected: keep a state of a central block and related entities (blocks and units). Related blocks and units are those which are stored in any of the variables of the central block (typically a processor or a memory block). in case of processors, all units controlled by the processor at the time of the snapshot's creation are also included.
- recording: a special snapshot which records the execution of several instructions. It can be created using the
snapshotinstruction, which specifies the target (either@this, or some other processor) and the number of steps to record. A recording snapshot shows the initial state of the processor and any connected blocks, and when selected in the snapshot list, allows navigation through individual instruction-related snapshots. Each instruction snapshot shows the variables and contains any objects used by the instruction. The number of individual snapshots stored in a recording snapshot is subject to the snapshot limit in the settings. - global: a global snapshot holds the state of all logic blocks on the map (i.e., only processors and memory cells, not all blocks in general).
Snapshots are always assigned to a specific block and are kept in a list for that block. When the number of snapshots reaches a (configurable) limit, older snapshots get removed from each block.
Connected, recording and global snapshots are reachable from any block included in them. A snapshot ceases to exist when it ages out of all blocks contained in it.
A connected snapshot can be created from a UI, using the Vars/Memory/Properties screens, or (in case of processors and memory cells) using the block configuration menu.
A snapshot instruction can create any type of snapshot, using any block as the central one. There's no rate limit on creating snapshots, but obviously there can be performance problems when the feature is abused.
Snapshots can be inspected using the Vars/Memory/Properties screens. A processor or memory state can be restored from a snapshot.
A snapshot can be deleted from the UI.
The memory block gets a configuration menu for creating and viewing snapshots. The processors' configuration menu is enhanced with buttons for creating and viewing snapshots.
A brief help is available on the Vars/Memory/Properties screens.
Snapshots can be completely deactivated in settings by setting the maximum number of kept snapshots to 0. When disabled, snapshots can't be created in any wany and no snapshot-related elements appear in the UI.
It is possible to activate creating a snapshot when a breakpoint is hit or an assertion fails.
Some kinds of schematics, e.g. subframe logic, may depend on the update order of processors on the map. To assist with developing this kind of logic, the mod can draw the update order index over all processors on the map. Additionally, it may also enforce the default update ordering (i.e., the update ordering derived from processor positions on the map) during map updates. Both of these options need to be activated in settings. Activating or deactivating the enforcement of default update ordering requires to reload the map.
Warning
Enforcing default update ordering changes the core behavior of the game. There's a possibility the performance or stability of the game will be negatively affected.
Caution
It is suspected the default update ordering enforcement may be incompatible with multiplayer/networked games. Turn off the enforcement of default update ordering before starting or joining such a game.
Mindustry is typically quite resilient when parsing mlog code and turns most unparseable lines to invalid statements. However, some errors in the mlog code are not recoverable and when Mindustry encounters them after importing the code from clipboard, it displays a very brief error message and leaves the processor empty.
In some cases, the faulty mlog code can be stored in schematics or in map files. Faulty code in schematic can be created by external tools, and both schematic and map files may contain faulty code when a backwards-incompatible change is introduced into a newer Mindustry version. This happened in build v160, for example, which changed the way backslashes in string literals are handled; when using bleeding edge builds, similar parse errors are also possible. Since both schematic building and map loading happen without direct user interaction, the parse errors are not reported to the user and the processors are left empty. This can be quite confusing, and it leads to the code stored in the processor being lost (irreversibly after a map is saved in case of processors stored in map files).
This mod installs special error handles to capture these errors. Then such a parse error occurs, it is logged in the processor's error log, and visually indicated on the map. The faulty code can be retrieved from the processor's log screen, using the Export faulty code to clipboard command from the Edit menu (there's no other way to access the code).
If the parse error detection scope is set to map &schematics, a faulty code is also kept in the processor, preventing it from being lost on a map save. The schematics detection scope doesn't protect faulty code in map files, but is potentially useful for detecting errors in schematic generated by external tools. This may cause problems with some other logic mods; if that is the case, preserving the faulty code can be separately turned off in settings.
Note
Parse error detection methods are rather intrusive and might lead to compatibility problems with other mods or even game crashes. If that happens, use the mod settings to lower the scope to schematics, or turn the detection off completely.
The custom instructions are used by Mindcode to provide debugging support or perform runtime checks. They can be used by other compilers too or by a manually written mlog.
When an assertion fails, the program execution stops at the given instruction, and an accompanying message is displayed above the processor.
This instruction asserts that the given condition is true. The instruction takes these parameters:
value,operator,comparison: specifies the condition to be checked.message: the error message to display in case the assertion fails. In the UI, the field is only displayed after tapping a button. The message may contain placeholders in the form{1},{2}or{3}forvalue,comparisonandoperator. Additionally, a variable name enclosed in curly braces ({and}) is replaced with the actual variable value. If the message is not a string or is an empty string, a default message is displayed.
This is a complex instruction, most useful to verify the value of a variable used as an index into an array is within bounds. Using out-of-bounds index for internal arrays can cause erratic, hard-to-diagnose behavior. The instruction takes these parameters:
type: keyword. Specifies the required type of the value being tested:any: any value is allowed,notNull: any value exceptnullis allowed,decimal: a numerical value is required,integer: an integer value is required,multiple: an integer value that is a specified multiple is required.
multiple: the required multiple in casetypeismultiple.min: the minimum allowed value. Corresponds to the{1}message placeholder.opMin: one oflessThanorlessThanEq, specifies whether the minimum value is included in the allowed range. Corresponds to the{4}message placeholder.value: the value being tested. Corresponds to the{2}message placeholder.opMax: one oflessThanorlessThanEq, specifies whether the maximum value is included in the allowed range. Corresponds to the{5}message placeholder.max: the maximum allowed value. Corresponds to the{3}message placeholder.message: the error message to display in case the assertion fails. In the UI, the field is only displayed after tapping a button. The message may contain placeholders in the form{1}to{5}, corresponding to the values and instruction parameters described above. Additionally, a variable name enclosed in curly braces ({and}) is replaced with the actual variable value. If the message is not a string or is an empty string, a default message is displayed.
This instruction compares an actual value to an expected value and displays the given message if they are not equal. The instruction takes these parameters:
expected: the expected value.actual: the actual value.message: the error message to display in case the assertion fails. In the UI, the field is only displayed after tapping a button. The message may contain placeholders in the form{1}and{2}for the expected and actual values. Additionally, a variable name enclosed in curly braces ({and}) is replaced with the actual variable value. If the message is not a string or is an empty string, a default message is displayed.
The values are compared using the strictEqual mlog operator.
This instruction compares the runtime data type to an expected value and displays the given message when the value is not of the expected type. The instruction takes these parameters:
expectedType: the expected data type. Supported data types are:numberstringcontentitemblockbulletTypeliquidstatusEffectunitTypeweatherteamunitCommandunitStanceunitbuildingprocessormemorymessagedisplaycanvaspropertyreadablewritablesenseable
actualValue: the value being tested.message: the error message to display in case the assertion fails. In the UI, the field is only displayed after tapping a button. The message may contain placeholders in the form{1}and{2}for the expected and actual values. Additionally, a variable name enclosed in curly braces ({and}) is replaced with the actual variable value. If the message is not a string or is an empty string, a default message is displayed.
This instruction must be used at the beginning of a code section which generates text into the text buffer (using any of the printing instructions, print, printchar or format). The assertprints instruction is then used to compare the output generated by the program to an expected string. The instruction takes these parameters:
position: output variable receiving the current position in the text buffer.
This instruction compares the output generated by the program to an expected string. The instruction takes these parameters:
position: the position in the text buffer at the beginning of the tested code (must be the variable used by theassertflushinstruction).expected: the expected string.message: the error message to display in case the assertion fails. In the UI, the field is only displayed after tapping a button. The message may contain placeholders in the form{1}and{2}for the expected and actual values. Additionally, a variable name enclosed in curly braces ({and}) is replaced with the actual variable value. If the message is not a string or is an empty string, a default message is displayed.
When the instruction finishes, the text buffer is restored to the state of the previous assertflush instruction.
Note
The content of the text buffer is not saved into the map file. Therefore, the asssertprint instruction may spuriously fail after a game is loaded from a save file.
This instruction comes with a condition (just like the jump instruction). When the condition is met, the game is paused in the exact state in which the breakpoint occurred and the processor with the breakpoint is centered on screen. No other instructions in the current processor or any other processors are executed after the breakpoint is hit, and all logic variables in all processors and contents of all memory cells should remain unchanged. However, it is possible that units and buildings do change their own state or the state of other units/buildings after the breakpoint hits, but before the game is properly paused.
Breakpoints are ignored in a multiplayer game.
Note
After unpausing the game, the execution continues as usual, but the order of instruction execution may be altered due to the processors being manipulated. Schematics depending on two or more processors executing in lockstep (e.g., subframe) may be affected.
This instruction displays an error message and stops the program execution. The instruction takes these parameters:
message: the error message to display.p1..p9: additional parameters to display in the error message.
A variable name enclosed in curly braces ({ and }, e.g. "Accessing value at index {index}.") in the message is replaced with the actual variable value. If the message contains placeholders in the form {1} to {9}, they are replaced by the corresponding parameters. If there are other parameters not used by the message, whose value is not the literal null, they are appended to the message one by one. String values are enclosed in quotes in this case. Numeric values in the color range are formatted as color literals (e.g., %e55454ff).
This instruction writes a message into the current processor's log. The logged messages can be viewed from the in-game UI.
level: the log level of the message, one ofdebug,info,warning, orerr.category: the message's category. Should be a short string, although any values are supported and used after converted to a string.message: the message to generate.p1..p9: additional parameters to display in the error message.
A variable name enclosed in curly braces ({ and }, e.g. "Accessing value at index {index}.") in the message is replaced with the actual variable value. If the message contains placeholders in the form {1} to {9}, they are replaced by the corresponding parameters. If there are other parameters not used by the message, whose value is not the literal null, they are appended to the message one by one. String values are enclosed in quotes in this case. Numeric values in the color range are formatted as color literals (e.g., %e55454ff).
Starts, stops or clears the profiling data of a given processor, including @this.
Fully restarts the target processor, resetting all processor variables to null. This instruction is intended to allow profiling or snapshot recording of processor's initialization code from another processor, e.g.:
restart processor1
snapshot recording processor1 100
The instruction ensures that at least one other instruction will be executed after it in the same frame, so that profiling or snapshotting of the target processor is guaranteed to start from the very first instruction.
If the goal is to activate profiling or snapshotting of teh current processor, a better way would be to add the profile or snapshot instruction at the beginning of the processor's code, or activate the Automatically profile all processors game rule.
Creates a snapshot of a given block. The instruction takes these parameters:
type: the type of snapshot to create:isolated: captures only the state of the target block.connected: captures the state of the target block plus the states of all blocks whose references are found in the variables of the target block - if the target block is a processor or a memory block.recording: creates an initial connected snapshot, followed by the specified number of instruction snapshots. The number of steps is limited by the maximum number of snapshots configured in settings.global: captures the state of all processors and memory blocks on the map (regular blocks are not included).
target: the target block (not used forglobalsnapshots).name: the name of the snapshot.
There's no rate limit on creating snapshots, but obviously there can be performance problems when the feature is abused.
This instruction writes a message into the game's log file. It is up to the user to avoid writing too many error messages into the file. The instruction takes these parameters:
level: the log level of the message, one ofdebug,info,warning, orerr.message: the message to generate.p1..p9: additional parameters to display in the error message.
A variable name enclosed in curly braces ({ and }, e.g. "Accessing value at index {index}.") in the message is replaced with the actual variable value. If the message contains placeholders in the form {1} to {9}, they are replaced by the corresponding parameters. If there are other parameters not used by the message, whose value is not the literal null, they are appended to the message one by one. String values are enclosed in quotes in this case. Numeric values in the color range are formatted as color literals (e.g., %e55454ff).
The mod adds a new game rule: Automatically profile all processors. When activated, all processors on the map are automatically profiled, whether they already existed when the map was loaded, or were added later. The setting remains stored with your map file, but the map is still loadable even if the mod is disabled or removed. When activated while playing the map, all processors start profiling immediately.
This option is particularly useful when trying to profile startup/initialization code of many processors on the map.
The Settings screen is divided into several sections.
- Triple tap speed: triple-tapping a block within the configured interval opens the Vars/Memory/Properties screen for the block.
- Override processor/memory config buttons: when active, the mod adds additional config buttons to processor's config menu and activates config menu for memory blocks. This action might interfere with custom config buttons added by other mods; when disabled, Mlog Dev Tools doesn't interfere with blocks' config.
- Left config button: selects the additional action available in the processor's config menu.
- Right config button: selects the additional action available in the processor's config menu.
- Show waits longer than: sets the minimal wait time specified in the
waitinstruction parameter which causes the wait to be indicated on processors. It is possible to completely hide the indication by moving the slider all the way to the left. - Processor updates per tick: to indicate the stopped and waiting processors, the mod needs to inspect the state of all processors on the map periodically. At most the given number of processors gets inspected in each tick. If there are a lot of processors on the map and the performance suffers, reducing this value may help.
- Visual warning: governs the use of visual effects on the map itself to draw attention to stopped or failed processors. Effects can be turned off completely, performed just once when the processor is stopped or failed, or performed periodically with a given interval.
- Indicate stopped processors: when a stopped processor is detected on the map, a message will be displayed, similar to the one shown when an assertion fails.
- Variable updates: number of game ticks between the frequency of variable updates on the Vars/Memory/Properties screens.
- Significant digits: the number of significant digits used when displaying decimal numbers in the Vars/Memory/Properties screens.
- Max instructions: allows increasing the instruction limit in logic processors. The increased limit may be used to add debugging code to your program, which otherwise wouldn't fit due to the standard instruction limit being exceeded.
- Disable breakpoints: disables breakpoints in processors - the execution continues on the next instruction without pausing.
- Breakpoint on failed assertions: when active, a failed assertion is handled in the same way as a breakpoint and the execution then continues on the next instruction. If breakpoints are disabled, the assertions are completely ignored.
- Detach camera on breakpoint: when a breakpoint hits, the camera is detached so that the processor remains in view. The original state of the camera is restored when the game is unpaused. In case detaching the camera causes some problems, it can be disabled.
- Start the profiler immediately: when active, the profiler is started as soon as the Profiler screen is opened.
- Stop the profiler on
stopinstruction: when active, the profiler stops when the stop instruction (or any other instruction setting the "stop" flag) is executed. - Syntax highlighting: activates/deactivates mlog syntax highlighting in the Profiler screen. The syntax highlighting might fail if some mods use implement custom instruction in a non-standard way, in which case it can be turned off here. When reactivated, the syntax highlighting reappears when the profiler is restarted.
- Log size: the amount of in-game log messages to keep per processor (see the
loginstruction). - Level limit: messages with level lower than the specified limit are ignored when generated by the
loginstruction. - Clear log on restart: when active, the log is cleared when the processor is recompiled or restarted.
- Generate system log messages: when active, some processor-related events are logged in the processor's log.
- Snapshot limit: the maximum number of snapshots kept per block. Setting this value to 0 deactivates snapshots entirely and removes snapshot-related features from the UI.
- Take a snapshot on a breakpoint: when enabled, a connected snapshot will be automatically created when a breakpoint is triggered.
- Take a snapshot on a failed assertion: when enabled, an isolated snapshot will be automatically created when an assertion fails.
- Display processor update order: draws each processor's update index on the map. Useful then developing schematics that depend on exact processor update order.
- Enforce default processor update order: ensures the processor update order corresponds tyo the map positions at all times. Requires a map reload for the change to take an effect. Warning: avoid in networked games!
- Parse error handling: determines how silent parse errors are handled:
- none: silent parse errors are not detected or indicated,
- schematics: silent parse errors are detected after a schematic containing problematic processor(s) is built,
- map & schematics: all silent parse errors are detected, either after a map is loaded, or after a schematic is built.
- Preserve faulty code in processors on the map: when a processor with faulty is loaded with a map or built from a schematic, the faulty code is preserved in it and is stored in the map again when saving. This means the faulty code won't be lost and can be retrieved even when the map is loaded and saved again. The map & schematics* scope is required for this option to work. This setting may cause some other logic mods to fail on the faulty code and may therefore be deactivated.
Note
Large values of the Snapshot limit setting may cause memory or performance issues.
