Conditions, loops and errors
Controlling the flow of a scenario in the Multogram Modules Constructor: IF with THEN and ELSE branches, WHILE, FOR and FOREACH loops, Break and Continue, Try-Catch and the [[_error]] variable, delay, ending a thread. How to write conditions.
These actions are in the Logic module. They don't do the work themselves; they decide which actions run and how many times.
The IF condition
Checks a condition and runs one of the branches: THEN if it is true, ELSE if it isn't. Either branch can be empty.
How to write a condition
| Example | True when |
|---|---|
[[AuthResult]] == true | the function returned true |
[[count]] >= 10 | the counter is at least 10 |
[[status]] != DOWN | the status isn't the word DOWN |
[[name]] == "John Smith" | the name matches the text in quotes |
[[account]] != "" | the variable holds something |
[[a]] > 0 and [[b]] > 0 | both numbers are greater than zero |
[[x]] == 1 or [[y]] == 1 | at least one equals one |
not [[done]] | done is false |
- Comparisons:
==,!=,>,<,>=,<=. Logic:and,or,not— or&&,||,!. - A variable in a condition is written only as
[[name]], a resource as{{name}}. A word without brackets is just a word. - Put text with spaces and punctuation in quotes.
The value is inserted with its own type: a number is compared as a number, text as text.
Loops
| Action | When to use it | Main parameters |
|---|---|---|
| FOR Loop | Repeat a set number of times | Start and end index, the index variable (cycleIndex) |
| FOREACH Loop | Go through each item of a list | The list ([[items]] or {{targets}}), the item variable (currentItem) |
| WHILE Loop | Repeat while a condition is true | The condition, the iteration limit |
Inside a loop the step number is available as [[cycleIndex]], and the FOREACH item as [[currentItem]] (the names
can be changed). Break exits the loop, Continue moves to the next step.
The WHILE iteration limit
So the scenario doesn't hang, WHILE has Max Iterations. An empty field stops with an error after
10,000 iterations when the module runs and after 1,000 in a test. 0 removes the limit: the loop runs while
the condition is true or until the task is stopped.
Error handling: Try-Catch
If an action in the TRY branch ended with an error, the remaining actions of that branch are skipped and
the CATCH branch runs. The error text is in the [[_error]] variable there.
TRY: Send Message → Add Log "Sent"
CATCH: Add Log "Not sent: [[_error]]"Without Try-Catch an error interrupts the thread's execution until a Try-Catch higher up catches it — in this function or in the one that called it. Wrap everything that depends on the outside world in Try-Catch: Telegram, network, files.
A failed action's result isn't written
If an action ended with an error, its result variable gets no value. Don't check it with a condition after such an action — handle the error in the CATCH branch.
Other logic actions
| Action | What it does |
|---|---|
| Delay | A pause in milliseconds: 1000 is one second. Accepts a [[variable]] or a {{resource}} |
| Call Function · Return | Run another function and return a value from it |
| Set Variable · Increment Variable | Working with variables, including global ones |
| End Thread | End the current thread |
| Stop Scenario | Stop the whole module, with all threads |
Pauses between Telegram actions
Similar actions in a row are a common cause of FloodWait and spam block. Put a Delay between sends and move the delay into a resource so the user chooses it.
Updated
Canvas and actions
How to build a module's scenario on the Modules Constructor canvas: add an action, configure its parameters, insert variables and resources, reorder, copy, disable and find an action.
Variables
[[name]] variables in the Multogram Modules Constructor: where they come from, value types, object fields and array elements, local and global variables in a multi-threaded module, viewing them in the inspector.