Calculator is a field in the "Editor" block that opens when you click on the tab with the same name. In this field, you can perform logical or arithmetic operations, execute functions of API requests from the builder, and available integrations.
It allows you to assign (declare) a variable for the client who has entered this block or update the values of existing variables. This functionality is especially useful for building funnels or tracking traffic sources.
The article with the same title explains how to work with variables.

Key points:
When working with the calculator, a variable name cannot start with a number.
Incorrect: <1_name>\ Correct: <name_1>.
A variable name cannot contain spaces; use an underscore "_" to separate words.\ Incorrect: <Client Name>\ Correct: <Client_Name>
For more details, read the article "Variables." ****ссылка
How to use the Calculator in the Builder
There is no need to use the #{} syntax when referencing a variable.
Example of calculating a variable’s value in the Calculator field:

Variables can be referenced either by their name directly or using the #{} syntax. All variables are automatically converted to floating-point numbers.
The calculator supports all necessary logical and arithmetic operations.
Comments in the Calculator
To add comments in the Calculator, use /* comment text /. This / */ syntax allows you to write both single-line and multi-line comments:

Remember to always close your comment with the */ tag at the end; otherwise, the comment will continue onto the next line.

Remember to include the closing tag for the comment, even if the comment is the last line in the "Calculator" field.
Don’t place comments directly one after another; there must be at least one empty line between them.
Constants
"E": Euler’s number e
Supported operators
"+": addition
"-"': substraction
"*" multiplication
"/": division
"%'": remainder of division
"^" "**": exponentiation
"==" "!=" ">" "<" ">=" "<=": comparison operators
"and" "AND" "&&": logical AND
"or" "OR" "||": logical OR
Important! Logical triggers with variables must be written in the "Variable" field, not in the "Trigger" field!
For example, the transition along the connector will occur if the variable Phone_Number is filled. See the figure below:

Note!
If you compare a variable to a value in quotation marks, make sure there are no spaces between the quotes and the value; otherwise, the block may fail to trigger or behave incorrectly!
Correct (no space before the quotation mark or after the value my_new_bot):
Incorrect (with a space before the quotation mark):
The IF Operator
You can now use conditional logic in the Calculator with the IF operator:
if (score > 90) {
grade = 'excellent'
bonus = 500
} else if (score > 70) {
grade = 'good'
} else {
grade = 'keep trying'
}

Conditions can also be written on a single line:
if (paid == 1) { status = 'ok' } else { status = 'wait' }
Each branch can contain any number of lines, including nested conditions and loops.
Only the branch whose condition evaluates to true is executed. All other branches are skipped entirely, so an undefined variable or an error in an inactive branch will no longer break the calculation.
#{variable} substitution also happens only inside the active branch.
The if(condition, if_true, if_false) method still works as before, but now only the selected branch is evaluated:
status = if(paid == 1, 'Paid', 'Waiting for payment: #{payment_url}')
When paid == 1, the branch containing #{payment_url} is not processed at all, so the variable does not need to exist.
whileandforLoops,break, andcontinue
i = 0
sum = 0
while (i < 10) {
sum += i
i += 1
}
for (i = 0; i < 10; i += 1) {
sum += i
}

Loops and conditions can be nested freely.
break exits a loop early.
continue skips the rest of the current iteration and moves on to the next one:
found = -1
for (i = 0; i < arr_len(items); i += 1) {
if (items[i] == target) {
found = i
break
}
}

Use for (;;) { ... } to create an infinite loop, subject to the iteration limit.
Infinite-loop protection
Each variable block allows a maximum of 256 iterations across all loops combined.
Once the limit is reached, all loops stop and the rest of the block continues running. Exiting a loop early with break helps preserve the available iteration limit.
How Variables Are Saved
Inside a loop, values are updated immediately. The loop condition and every subsequent line always use the latest values.
Only the final values are saved, once, after the loop finishes, including when it exits through break. No matter how many iterations are performed, only the final result is written.
When an error occurs inside a loop, none of the changes made by that loop are saved. Values created during the iterations are temporary, and the previously saved values remain unchanged.
A for loop variable, such as i, is internal. It exists only while the loop is running, is never saved, and disappears when the loop finishes.
Local Variables
The local keyword creates a temporary internal variable. It remains available for all calculations until the end of the block, but is never saved to the customer profile.
This means temporary variables such as tmp and buf no longer need to be removed manually with del.
local tmp = get(#{data}, 'items')
local count = arr_len(tmp)
if (count > 5) {
result = 'many'
}

When the customer already has a regular variable with the same name, it remains unchanged. The local variable simply shadows it temporarily.
The += and -= Operators
counter += 1
balance -= price
greeting += ', hello!'
These operators work with numbers and strings anywhere in the block. For strings, += appends the new text to the existing value.
Multiline Expressions and Unquoted JSON
Long expressions no longer have to fit on a single line. Previously, a line break could cause the entire block to fail, which was a common issue when working with the Calculator.
Function calls can now span multiple lines. Simply add a line break after a comma between arguments.
Objects and arrays can also be written directly, without wrapping them in quotes, and may span as many lines as needed:
cfg = {
"greeting": "Hello!",
"work_hours": [10, 19]
}
hello = cfg["greeting"]

There is only one restriction: text inside quotes, such as '...', cannot contain a line break.
Add line breaks after commas between function arguments, or anywhere inside {curly braces} and [square brackets].
AI-Powered Validation
Any Calculator code can be checked with AI. It will identify potential issues and errors involving methods, functions, operators, conditions, and loops.
