Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macros

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Copying and moving objects

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Accessing the file system

Accessing the clipboard

Sample Macros

Concepts

Code Structure

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: May 01, 2026
Also available as a single HTML file

Onetastic Macro Documentation > Concepts > Code Structure

Code Structure

In Onetastic Macro Language, a program is a sequence of Statements. Each statement normally occupies one line. The number of tab characters at the start of a statement (its indentation level) determines which block the statement belongs to.

Blocks and Indentation

Control flow statements such as for, foreach, if, while, and switch introduce a block of child statements. Statements belonging to a block must be indented exactly one tab deeper than their block header. Statements at the same indentation level as the header are outside the block.

Copied!
$sum = 0 for ($i = 1, $i <= 5, ++$i) $sum += $i // $sum is now 15, outside the loop ShowMessage($sum)

User-defined function follow the same rule. The statements inside a function body must be indented one tab deeper than the function signature. This applies to all functions including Main.

Copied!
function Add($a, $b) return $a + $b function Main($arg, $context) $result = Add(3, 4) ShowMessage($result)

Nested Blocks

Blocks can be nested inside each other. Each additional level of nesting requires one more tab of indentation.

Copied!
for ($i = 1, $i <= 3, ++$i) if ($i > 1) ShowMessage($i) // two levels deep

Multi-Line Statements

A statement can be split across multiple physical lines by ending a line with a backslash \. The next line is treated as a continuation of the same statement. This is useful when a statement is long and would be difficult to read on a single line.

Copied!
$result = String_Replace( \ "the original text", \ "original", \ "replaced")

The indentation on continuation lines is purely cosmetic (it does not affect which block the statement belongs to). Only the indentation of the first line of a statement determines its block membership. Multi-line statements work inside blocks as well:

Copied!
for ($i = 1, $i <= 5, ++$i) $message = "Item " + \ String($i) ShowMessage($message)

Comments can also appear on continuation lines:

Copied!
$result = String_Replace($text, /* search: */ \ "original", /* replace: */ \ "replaced")

Reference

Statements

Hierarchy Objects

Page Objects

Other Objects

Functions

Array Functions

Clipboard Functions

Data Store Functions

Data Type Specific Functions

Date/Time Functions

Dialog Box Functions

File System Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

Special Functions

String Functions

Window Functions