# Number Variable Rules

{% hint style="info" %}
Use Number Variables to track the number of times a viewer performs an action or to store a score or any other number.
{% endhint %}

Example Experience where you can track the number of times the viewer enters a zone:

(Try walking into the blue zone and see the count increment)

{% embed url="<https://demo.gmetri.com/variables_demo>" %}
Example Experience to track how many times the viewer enters the blue zone
{% endembed %}

These are the rules that were used in the above experience:

<figure><img src="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mgll1jjQMRTVj7p6n7g%2Fuploads%2Fg45VURelNSWyQ3FY2EuO%2Fimage.png?alt=media&#x26;token=ad42072b-3be8-4fbb-afd9-351c27f99af1" alt=""><figcaption><p>Rules - Number Variables</p></figcaption></figure>

## Number: When Rules

<figure><img src="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mgll1jjQMRTVj7p6n7g%2Fuploads%2FKnr7P8AjKSsNUtQH32q8%2Fimage.png?alt=media&#x26;token=8eb15d8b-cb09-4659-b874-80ae624a0c22" alt=""><figcaption><p>Number: When Rules</p></figcaption></figure>

1. **changes**:  Gets triggered if the number variable undergoes a change.
2. **is between**: Gets triggered if the number variable is within a certain range.
3. **is =**, **is >**, **is > OR =**, i**s <**, i**s < OR =**: Comparison operators that trigger when the given condition becomes true.
4. **is in the list / is not in the list**: A certain action can be triggered if the number value exists in a given comma-separated list.

<figure><img src="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mgll1jjQMRTVj7p6n7g%2Fuploads%2Ffyk4McFYpyH77ZTVyrTk%2Fimage.png?alt=media&#x26;token=8124693b-a99c-4701-bab4-aba51633ca68" alt=""><figcaption><p>Is In List Rule</p></figcaption></figure>

## Number: Then Rules

1. **reset to default value** - This will set the variable back to its default value.
2. **set to number** - This action allows you to set the variable to a particular number.
3. **set to formula** - This action enables you to use a formula that generates results to set the value of the variable.
4. **add number** - This action allows you to add a particular number to the variable.
5. **capture data** - This action copies the value from the "When" side of the rule. Check [String Substitution](/metaverse/build/variables/string-substitution.md#capturing-user-input).
6. **add captured value** - This action adds the captured value to the variable (instead of replacing it with the value).

<figure><img src="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mgll1jjQMRTVj7p6n7g%2Fuploads%2FuxIMAk6cS0rkBdMvF2yL%2Fimage.png?alt=media&#x26;token=4515483d-2052-45bd-99cd-444999e86eae" alt=""><figcaption><p>Number: Then Rules</p></figcaption></figure>

## Number: Formulas

You can do a lot with the Then option *set to formula* for Numbers.

### Mathematical Expressions

You can write any formula in the "Set to formula" value to get it evaluated by GMetri.

{% hint style="info" %}
Formula expressions also support [Variable Substitution](#using-variables-through-text-substitution).
{% endhint %}

The following types of expressions are supported:

|                    Input                   |       Result      | Explanation                                                      |
| :----------------------------------------: | :---------------: | ---------------------------------------------------------------- |
|                  **2+3-1**                 |         4         | Addition and Subtraction operator                                |
|                 **2\*5/10**                |         1         | Multiplication and Division operator                             |
|         **tan45** *or* **tan(45)**         |         1         | Trigonometric Function (tan in Degree mode)                      |
|         **tan45** *or* **tan(45)**         | 1.619775190543862 | Trigonometric Function (tan in Radian mode)                      |
|      **Pi1,15,n** *or* **Pi(1,15,n)**      |   1307674368000   | Product of Sequence                                              |
|   **Sigma1,15,n** *or* **Sigma(1,15,n)**   |        120        | Sum of Sequence (also called summation)                          |
|                   **2^3**                  |         8         | Exponent (note this operator is left associative like MS Office) |
|                   **5P3**                  |         60        | Permutaion Method to calculate all the permutaions               |
| **sincostan90** *or* **sin(cos(tan(90)))** | 0.017261434031253 | Multiple functions with or without parenthesis (both works)      |

### Random Number

Set the "Set to formula" value to `random_<from>_<to>` to generate a random number.  Replace "\<from>" and "\<to>" with numbers, no spaces in between - like `random_0_5`. For example, if you want to generate a random number between 3 and 8, you should set this to `random_3_8`.

### Current Time

Set the "Set to formula" value to `current_time` to save the current epoch time (in ms) in a number variable.

{% embed url="<https://demo.gmetri.com/randomno_demo>" %}
Number: formulas
{% endembed %}

Rules used in the above experience:

<figure><img src="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mgll1jjQMRTVj7p6n7g%2Fuploads%2FlifI1RyFpwLlziYBq4QY%2Fimage.png?alt=media&#x26;token=be0e0f4b-c22f-4fd8-a293-99ba24aa66ed" alt=""><figcaption><p>Formula based rules</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gmetri.com/metaverse/build/rules/number-variable-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
