Your own code
The Code Execution module in the Multogram Modules Constructor: built-in JavaScript, Python, Node.js, CMD, Bash and PowerShell. How variables and resources are inserted, how to return a result, packages.
If a ready-made action isn't enough, write a piece of code — the Code Execution module runs it right in the scenario.
Languages
| Action | Language | When to choose it |
|---|---|---|
| Execute JavaScript (ECMA) | Built-in JavaScript | Calculations and data processing. Nothing to install; no require, Node.js modules or asynchrony |
| Execute Python | Python | Python libraries, complex processing |
| Execute Node.js | Node.js | npm packages, familiar JavaScript |
| Execute CMD, Execute PowerShell, Execute Bash | Command shells | System commands and scripts |
Packages are installed with the Install Python Package and Install Node.js Package actions and removed with the matching actions. Python and Node.js must be installed on the module user's computer; the built-in JavaScript needs nothing — choose it for modules you hand out.
Variables and resources in code
Before running, [[variables]] and {{resources}} are inserted into the code according to where they are:
| Where the reference is | What is inserted | Example |
|---|---|---|
| In the code | A value of its own type: text in quotes, a number, an object | var n = [[count]]; → var n = 5; |
| Inside a quoted string | Just text, without extra quotes | print("phone=[[phone]]") → print("phone=79000000000") |
Write [[x]] right in the code to get the value; put it in quotes only if you need it as
text. References in comments are not inserted.
A typo in a name won't cause an error
A non-existent variable turns into null (in Python — None), and execution continues. If
the result is odd, check the names first.
How to return a result
- The program's output (
print(...),console.log(...)) goes into the action's result variable. - An assignment
[[name]] = valueright in the code creates or changes a scenario variable — objects and arrays are saved as they are. Works in Python, Node.js and the built-in JavaScript.
var digits = ('' + [[phoneInput]]).replace(/[^0-9]/g, '');
[[phone]] = { ok: digits !== '', value: digits };
print(digits ? '+' + digits : 'EMPTY');After this action the scenario has a [[phone]] object with the ok and value fields, and the result
variable holds the printed string.
When you don't need code
A lot is already available as ready-made actions: strings, JSON, regular expressions, math, date and time — see Modules and actions. Ready-made actions are easier to read and check; leave code for what they can't express.
Updated
Threads and accounts
How a Multogram module runs in several threads: what a thread is, how to hand accounts out to threads without repeats, when a module's task ends, shared and local data, the task's log and statistics, running functions in parallel.
Testing and debugging
How to check a module in the Multogram Modules Constructor: the test point, single and full tests, testing one action, resource test values, the variables and logs inspector, finding the causes of errors.