No-Code Workspace — Block Reference

SystemBlock usage recipe

Add Code (CUSTOM_CODE)

Adds Lua code directly to the flow

Documented for app version 1.0.50Updated:

Block Preview

Captured from the in-app Visual Builder block card in the English UI.

English UI
Add Code (CUSTOM_CODE) block card

What Does It Do?

Write Lua for work that blocks cannot express. Access Region, Asset, Touch, Point, Snap, Setting, Color, Math, Str, System, and Event, plus the macro variables.

When to Use?

1

Custom logic that is hard to build with blocks

2

Direct calls to APIs such as Region, Asset, Touch or Snap

How to Use?

1

Write your Lua code; several lines are fine

2

Validation before saving and running checks the Lua syntax

Parameters

Lua Code

Lua code to run

Example Usage

1

Snap.screenRefresh()

2

local r = Region(0, 0, 500, 500)

3

local button = Asset.image("button.png")

4

local found = r:find(button)

5

if found then click(found) end

Combinations / Used With

1

TRY_CATCH + CUSTOM_CODE: catch runtime errors

2

COMMENT + CUSTOM_CODE: explain what the code does

Tip

Adds Lua code directly to the flow

Warnings / Cautions

1

A syntax error is rejected by validation; the macro does not start

2

Runtime errors stop the macro unless they are inside Try/Catch

3

An empty code block shows a warning and does nothing

4

Some Lua functions such as loadstring, require and debug are unavailable for safety

Step-by-Step Mastery: Basic → Advanced → Pro

The same block at three levels: a quick start, the real options, and professional techniques.

Basic

Add Code (CUSTOM_CODE) lets you do things that are hard or impossible with blocks by writing Lua directly. You can access APIs like Region, Asset, Touch, Point, Snap, Setting, Color, Math, Str, System and Event, write several lines and use the macro variables. Validation before saving and running checks the Lua syntax, so the macro does not start with broken code. An empty code block only shows a warning and does nothing.

Advanced

CUSTOM_CODE runs inside a safe sandbox: dangerous Lua globals are removed, so loadstring, loadfile, dofile (dynamic code), require (module loading), debug, getfenv/setfenv, rawset and collectgarbage are unavailable. You work with the allowed high-level APIs (Region, Touch, Snap, System, etc.) and can read and write values set with SET_VARIABLE. Syntax is checked by validation; errors raised while running stop the macro, so wrapping risky code in TRY_CATCH is strong protection. Do not write a loop without an exit.

Pro

Reserve CUSTOM_CODE for last-resort and delicate work; doing standard things (list loops, assignment, comparison) with FOR_EACH / SET_VARIABLE / COMPARE blocks is more readable and less error-prone. The rule for writing inline Lua safely: keep it small, make it do one thing, always wrap it in TRY_CATCH, and add a COMMENT next to it explaining what it does — so even a non-coder user understands the macro. Don't reach for the blocked calls (loadstring/require/debug); the sandbox nils them and trying errors. Typical strong uses: generating bounded coordinates on an isolated test screen to verify touch-target coverage, building a table for FOR_EACH, or a custom search with Region/Asset that blocks can't express. Work with a fresh frame after Snap.screenRefresh(); a stale frame yields a wrong match.

Real-World Scenarios — Step-by-Step Recipes

Small, reproducible examples that combine several blocks — build them straight into your own macro.

Validate a random point inside a bounded test region
  1. 1Add CUSTOM_CODE on an isolated test screen
  2. 2local x = math.random(100, 900)
  3. 3local y = math.random(200, 1800)
  4. 4click(Point(x, y)) and verify the expected test result
  5. 5For safety wrap the block in TRY_CATCH and cap the iteration count
Capture the screen and run a custom search
  1. 1CUSTOM_CODE: Snap.screenRefresh()
  2. 2local r = Region(0, 0, 500, 500)
  3. 3local button = Asset.image("button.png")
  4. 4local found = r:find(button)
  5. 5if found then click(found) end
  6. 6Wrap the block in TRY_CATCH and add a COMMENT explaining it

Which Blocks to Pair With — Pro Combinations

This block is useful on its own — but it shines when paired with the right partners.

+ TRY_CATCH

Catches the inline Lua’s runtime error and keeps the macro running; the natural partner for risky code.

+ SET_VARIABLE

Write the result of a complex calculation into a variable and use it in later blocks.

+ FOR_EACH

Build a table with CUSTOM_CODE, then loop over it with FOR_EACH without writing loop code.

+ LOG

Log the intermediate/final result of the inline calculation to verify behavior.

+ COMMENT

Explains the inline Lua's purpose for a non-coder user; the macro documents itself.

Common Mistakes and Fixes

Trying to save code with a syntax error; validation rejects it and the macro does not start. Fix the line named in the message.

Reaching for sandbox-blocked calls (loadstring, require, debug, dofile, setfenv, rawset, collectgarbage); they are nil and trying errors.

Needlessly writing standard tasks (assignment, loops, comparison) in Lua; blocks are more readable and safer.

Searching on a stale frame; using find/region without calling Snap.screenRefresh() yields wrong matches.

Pro Tips

Keep inline Lua small and single-purpose and always wrap it in TRY_CATCH; one bad line shouldn't take down the whole macro.

Add a COMMENT beside it so even a non-coder user understands what the block does.

Use Lua only for what blocks can't express; leave the rest to FOR_EACH/SET_VARIABLE/COMPARE blocks.

This Block's Code (Editor View)

Lua

The Lua below is what the Code Editor generates for this block with sample settings. Adding cases, branches, actions or loops, or changing settings, extends the generated code accordingly. Study it to see what the block does under the hood, to learn Lua, or to copy and adapt it. Use the Copy button (top-right) to paste it into the Code Editor, or “Try in Editor →” to run it in the live editor.

System.log("ok")

Note: generated code can evolve across versions; helper names (e.g. _reg1, m1) and internal optimizations may change. The logic and the called APIs reflect the block’s behavior.

Block ↔ Lua Mapping →

Shared Controls for This Block Family

The guidance below is not identical for every block. It summarizes the professional controls that most often repeat in the selected block family.

⚙️Command Type

SYSTEM and PANEL_CONTROL first choose a command type; the rest of the fields only make sense in that context.

🧾Argument Semantics

arg1/arg2 or panel fields do not mean the same thing across every command; fill them according to that command.

🧪Dry-Run Thinking

Testing risky system actions with LOG or NOTIFY before going live makes builder flows safer.

🕒Synchronization Waits

Add short waits after app launches, panel state changes, or settings-navigation steps.

Builder vs Lua Boundary

Raw touch pointer lifecycle stays code-first

TOUCH and TOUCH_BREAK cover recipe-style touch flows. Raw pointer choreography such as Touch.down, Touch.move, Touch.up, Touch.dispatch, Touch.reset, Touch.breakAll, and Touch.releaseAfter is not exposed as a first-class builder block.

Touch.downTouch.moveTouch.upTouch.dispatchTouch.resetTouch.breakAllTouch.releaseAfter
Bounded dialog design is builder-backed; freer composition stays code-first

The DIALOG block and dialog designer cover a bounded field set in the builder: Info Text, Text Input, Checkbox, Description, Radio Group, Dropdown, Multi Select, Tab Group, Date Time, Number Range, Slider, Image Picker, Color Picker, File Picker, Recorder Picker, Tag, Signature, and Spacer. The buttons are designed too: the Positive button and Negative button tabs set each button’s text, background, and border color, corner radius, and minimum height next to a preview. Freer Setting.builder composition, multi-step wizard flows, and mixed HUD/dialog choreography still do not map 1:1 into the builder.

Coming soonv1.0.51Two more fields: Agent Detect references (agent_detect_editor) lets the user pick a saved reference set or add and edit references, and Save confirms the selection; Navigation setup editor (navigation_editor) edits a saved map, marker and route from the Dialog and returns the setup and route selection without moving the character.

Setting.builderDialogHudTextViewAgentDetectEditorNavigationEditor
Advanced HTTP request chaining stays code-first

HTTP_GET, HTTP_POST, and HTTP_PUT cover common fixed-method flows; HTTP_REQUEST covers one bounded request with method, header lines, body, content type, query parameters (GET and DELETE), timeout, and a bounded retry. These blocks never throw; they write the status code (-1 on a network failure). Cookie handling, chained request objects, and lower-level client flows still need the code editor.

Request()Request.setCookieRequest.getCookiesCUSTOM_CODE
General programming surfaces stay code-first

The MAP, LIST, JSON_PARSE, REGEX_MATCH, and METRICS blocks cover the everyday cases: map actions, a static list, reading a value from a JSON path, regex match, find, replace, and split, and metrics actions. The rest of the Map, Array, JSON, Regex, and Metrics APIs (for example Array sort, filter, and map) is broader than the builder recipe model and stays on the CUSTOM_CODE and code editor side.

MapArrayJSONRegexMetrics
Low-level runtime and Lua composition stays code-first

Runtime helpers, raw Request objects, Lua built-ins such as print/pcall/xpcall, and free-form object chaining patterns are represented through CUSTOM_CODE or the code editor.

RuntimeRequestprintpcallxpcallCUSTOM_CODE

Debug Mode and Breakpoints

Each block card now exposes an independent breakpoint toggle. When enabled, the breakpoint preference is stored with the block.

Breakpoints are only emitted into runtime code when Debug Mode is enabled from Visual Builder settings. When Debug Mode is off, breakpoints stay saved but do not pause execution.

Use ASSERT for fail-fast validation, and use breakpoints for step-by-step tracing and controlled pauses in the same flow.

Variable Scope

1

Variables defined with SET_VARIABLE are accessible throughout the macro (global scope). All blocks can read/write the same variable.

2

However, a variable defined inside a GROUP will be 'nil' (undefined) until the GROUP executes. Blocks outside the GROUP using this variable may produce unexpected results.

3

FOR_EACH loop variables (item and index) only carry valid values inside the loop body. Outside the loop they are outside local scope and should not be used.

4

TRY_CATCH error variable is only valid within the catch block. If the try block succeeds, the catch branch is not entered and the error variable remains undefined.

5

TIP: Before using a variable inside a GROUP, assign a default value with SET_VARIABLE outside the GROUP. This way the variable won't be nil even if the GROUP has not run.

Inline Expressions

You can embed variable values and calculations into text fields using {{ expression }} syntax. Expressions inside double curly braces are evaluated as Lua code and the result is inserted into the text.

Syntax
{{ expression }}
Examples
Skor: {{ score + 1 }} → "Skor: " .. tostring(score + 1)
{{ name }} kazandı! → tostring(name) .. " kazandı!"
X:{{ x }} Y:{{ y }} → "X:" .. tostring(x) .. " Y:" .. tostring(y)
Supported Blocks
SET_VARIABLELOGCOMPARECLIPBOARD_WRITENOTIFY_TOASTKV_SET
Security Note

Expressions are checked by the sandbox policy. Security-sensitive calls like loadstring, require, debug are automatically blocked.

General Tips

1

Keep scan regions as small as possible — improves speed, reduces false matches.

2

Always add an exit condition when using infinite loops (BREAK, timeout, or conditional exit).

3

Use network operations and error-prone steps inside TRY_CATCH.

4

If you need global error handling, use the Error Handler (ERROR_HANDLER) block as a singleton in the project.

5

Small coordinate offsets (CLICK/SWIPE) improve tap accuracy across different DPI and screen scales.

6

Customize macros with Dialog block — different parameters each run.

7

Define repeating steps once with GROUP_CALL, call from many places.

Cross-macro local library

Local Shared Macro Area

The Local Shared Macro Area moves blocks, variables, dialog fields, gallery assets, and imported media dependencies between macros on the same device. It is device-local, not cloud sync, not Firebase sharing, and not a replacement for public macro sharing.

Professional usage model: put a reusable login flow, common scan region, shared dialog form, variable group, template image, color profile, replay recording, or imported PLAY_SOUND media file into the shared area from one macro, then import it from the relevant + menu in another macro.

VISUAL_BLOCKSVARIABLESDIALOG_FIELDSTEMPLATE_IMAGECOLOR_SWATCHREPLAY_RECORDMEDIA_FILE
1

Send to the shared area

When one item or a multi-selection is active, the shared-area button can copy the selected part from the workspace, group, true/false action branch, dialog, and variables surfaces into the device-local library.

2

Import into another macro

The shared-area entry under the + menu imports the selected item into the surface that opened it. Main workspace, group, action branch, dialog, and variables each receive the compatible item type.

3

Share gallery assets

Gallery items include template images, color swatches, replay records, and imported audio/media files. They can move between macros on the same device so repeated templates, colors, recordings, and PLAY_SOUND media assets do not need to be captured again.

4

Keep it clean

The shared area is not a permanent dumping ground. Delete stale shared items from the shared-library panel; imports create a copy in the target macro and do not rewrite the source macro flow.

Checkpoint: after importing, review block names, linked template/image/color/record/media assets, and variable names in the target macro. The shared area creates a copy; delete stale shared items from the shared-library panel to keep the library clean.

AI assistant

Build a block chain with MH AI in natural language

Tell MH AI what you want in plain language; it proposes the right block sequence and lands it in the workspace after you approve. In the current release it works with cloud providers such as Gemini, Claude, and OpenAI; on-device local models are on the roadmap.

Learn more →