Skip to content
Docs
Modules Constructor

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

ExampleTrue when
[[AuthResult]] == truethe function returned true
[[count]] >= 10the counter is at least 10
[[status]] != DOWNthe 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]] > 0both numbers are greater than zero
[[x]] == 1 or [[y]] == 1at 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

ActionWhen to use itMain parameters
FOR LoopRepeat a set number of timesStart and end index, the index variable (cycleIndex)
FOREACH LoopGo through each item of a listThe list ([[items]] or {{targets}}), the item variable (currentItem)
WHILE LoopRepeat while a condition is trueThe 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

ActionWhat it does
DelayA pause in milliseconds: 1000 is one second. Accepts a [[variable]] or a {{resource}}
Call Function · ReturnRun another function and return a value from it
Set Variable · Increment VariableWorking with variables, including global ones
End ThreadEnd the current thread
Stop ScenarioStop 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

CookiesPrivacy Policy

We use essential cookies to run this site. With your consent, we will also use analytics cookies to improve it and marketing cookies to credit whoever referred you. You can change your choice at any time.