Skip to main content

num to $var

The num to $var block is used to receive an integer number from the client and save it to a variable.

How to add it?

To add the block, select Add blockMore blocksnum to $var.

The values of the variable received by the bot can be used in subsequent steps of the script (for example, to address the client by name), exported to .csv or submitted to an external system (such as your database).

How does the block work?

The num to $var block expects the client to enter a number (including its text representation). The block will understand “5”, “five” or even options like “I believe it’s 5”.

You can use the $NUMBER system variable in the Intents block to accept a number.

How to use it?

The num to $var block contains fields that can be filled out depending on your requirements.

HTML markup

You can use HTML markup in the bot messages. To do this, activate the Use HTML markup in the message toggle.

caution
Not all channels support HTML markup. Learn more about this in the HTML markup article.

Message

This field contains the “Enter a number” text by default. You can put any message here, such as a question or a prompt to input some data. For example, “How old are you?”, “How many kids are you going to take with you?”, “How many pets do you have?”, etc.

Variable name

You can enter the name of the variable that will be used to store the client response in this field.

The variable name can be just about any string, but there are certain rules: use the Aa-Zz, _, 0-9 characters. Start the name with Aa-Zz. You may not use reserved JS words.

Learn more here. You can also find some info about JavaScript variables.

“From” and “To” fields

These fields define the range of values expected from the client. For example, if you ask about the age of a child, you can specify “from 0 to 17”.

The default range is 1 to 5.

Error message

This message will be displayed if the client enters a number our of the range (less than “From” or greater than “To”).

You can also specify multiple error messages.

After you specify two error messages, a new error message field will appear. As you add more error messages, additional fields for more error options will appear. They will be selected and displayed randomly:

The default error message is “Enter a number from 1 to 5”.

Data type

There is a concept of the data type in programming languages. The type of the number the bot stores in a variable will be “number” instead of “string”.

What’s next?

After you store the number to a variable, you can perform operations with it, such as:

Display this variable in a Text block:

You are $number year(s) old

or

There will be $number children with you, right?

Use this variable in calculations in JS expressions within a Conditions block.

Submit this variable (the value from it) to the desired service, such as