# Comparisons

## Use Cases:

* Buying items
* Checking if a player has completed a task
* Verifying if a player possesses the correct item
* Determining if a player has specific items equipped
* Triggering events based on value ranges
* Initiating random events based on values
* Unlocking quests
* Verifying puzzle completion by the player
* Checking if the player has entered the correct sequence

{% hint style="warning" %}
Set **Broadcast Type** to *All* or *Rules* to send messages from objects to the Rules System.
{% endhint %}

## Compare Numbers

{% tabs %}
{% tab title="About" %}
With the **Compare numbers** Rule it is possible to compare a number variable with another value. When the condition is met a message will be sent. This can be used to trigger a victory event when a player scored enough goals or to define which team has won in a multiplayer game. The Rule can be set up to check immediately upon receiving the trigger or can wait for the condition to be true to send the outgoing message.

It is possible to use different conditions like equals or greater than to cover a multitude of uses.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FVboPj9FCcpzyKMjwHFZP%2Fimage.png?alt=media&#x26;token=918767c7-af32-41d9-912a-97e82364931e" alt="" width="330"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Details" %}
**Required message**&#x20;

The message to activate this tree. Every time this message is broadcast the tree will be triggered.

**Number variable to compare**&#x20;

This defines the number variable that is compared by this rule.

{% hint style="info" %}
During the comparisons this value will be 'A'.
{% endhint %}

**Condition**&#x20;

The condition defines how two values are compared. There are multiple selectable options:

* **Equals:** When both values are the same, the message will be sent. **A = B**
* **NotEquals:** When both values are different, the message will be sent. **A ≠ B**
* **Greater:** When the Number Variable’s value is higher than the compare value, the message will be sent. **A>B**
* **GreaterEquals:** When the Number Variable’s value is higher or the same as the compare value, the message will be sent. **A≥B**
* **Lower:** When the Number Variable’s value is lower than the compare value, the message will be sent. **A\<B**
* **LowerEquals:** When the Number Variable’s value is lower or the same as the compare value, the message will be sent. **A≤B**

**Number variable to compare with**&#x20;

There are three modes to define the number the initial number variable is compared with:

* **Variable** will allow you to define an existing variable to modify the number. This variable can be modified elsewhere using the **Roll a Random Number, Add/Subtract number** or **Set number value** Rules. A dropdown menu will appear to select a variable.
* **Fix value** will allow you to set up a constant value. An input field will appear to enter the number value.
* **Message Argument** will allow you to use an argument sent within the message. The message has to be created with an argument of the number type for it to be selectable here. A dropdown menu will appear to select the message argument.

{% hint style="info" %}
During the comparisons this variable will be 'B'.
{% endhint %}

**Comparison duration**&#x20;

With this checkbox ticked the condition will not only be checked when the Rule is activated but will wait until the condition is true and sent the **outgoing message.**

**Message to send**&#x20;

The outgoing message that is sent when the condition is met.
{% endtab %}
{% endtabs %}

## Compare True/False

{% tabs %}
{% tab title="About" %}

### Compare True/False

This rule compares the value of the true/false variable selected with another true/false variable or value.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FiSEhuQNXgGscM8DifumI%2Fimage.png?alt=media&#x26;token=7958faf1-02a1-4b99-a03c-231b4f5fc9fc" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Details" %}

#### Required Message

Select the incoming message to trigger the rule.

#### True/false variable to compare

Select the true/false variable to compare.

#### Condition

Select a condition to compare.

#### True false variable to compare with

Select what to compare the true/false variable with:

* Variable - Select a second variable to compare with.
* Message Argument - The Required Message that triggers this rule may include a message argument of true/false type.
* Fixed Value - Use the toggle to select a fixed value of True or False.

#### Comparison Duration

Define how often the condition is checked once the rule is triggered:

* Once - The rule will only check when it is triggered by the Required Message.
* Constantly - The rule will always check the condition until it is met.

#### Message to Send

Select the outgoing message to be sent when the condition is met.
{% endtab %}
{% endtabs %}

## If/Else

{% tabs %}
{% tab title="About" %}
This rule checks a true/false value and sends a message if either true  or false.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fk1v9W9EtNLY0R8ofGTiD%2Fimage.png?alt=media&#x26;token=9239ca43-a7f2-4302-9414-7d2745e363a1" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Details" %}

#### Required Message

Select the incoming message to trigger the rule.

#### True/False Value

Select a true/false value to check if it is true or false:

* Variable - Select a true/false variable to check.
* Message Argument - The Required Message that triggers this rule may include a message argument of true/false type to check.
* Fixed Value - Use the toggle to select a fixed value of True or False.

#### Message to Send When True

Message to send if the selected true/false value is true.

#### Message to Send When False

Message to send if the selected true/false value is false.
{% endtab %}
{% endtabs %}

## Check if number is in range

{% tabs %}
{% tab title="About" %}

#### **Set up a Lootbox or adjust the result of something depending on the score of the player.**

The **Check if number is in range** Rule will check whether a value is within a predefined range. The Rule can be set up to check immediately upon receiving the trigger or can wait for the condition to be true to send the outgoing message.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fas5FUORelsHX5Ru9x2sJ%2Fimage.png?alt=media&#x26;token=1a6af785-05c8-4a09-b4a2-4de6ccdee756" alt="" width="330"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Details" %}
**Required message**&#x20;

The message to activate this tree. Every time this message is broadcast the tree will be triggered.

**Minimum value**&#x20;

There are three modes to define the lowest value the number can be for the comparison to return true:

* **Variable** will allow you to define an existing variable to modify the number. This variable can be modified elsewhere using the **Roll a Random Number, Add/Subtract number** or **Set number value** Rules. A dropdown menu will appear to select a variable.
* **Fix value** will allow you to set up a constant value. An input field will appear to enter the number value.
* **Message Argument** will allow you to use an argument sent within the message. The message has to be created with an argument of the number type for it to be selectable here. A dropdown menu will appear to select the message argument.

**Maximum value**&#x20;

There are three modes to define the highest value the number can be for the comparison to return true:

* **Variable** will allow you to define an existing variable to modify the number. This variable can be modified elsewhere using the **Roll a Random Number, Add/Subtract number** or **Set number value** Rules. A dropdown menu will appear to select a variable.
* **Fix value** will allow you to set up a constant value. An input field will appear to enter the number value.
* **Message Argument** will allow you to use an argument sent within the message. The message has to be created with an argument of the number type for it to be selectable here. A dropdown menu will appear to select the message argument.

**Number variable to compare**&#x20;

There are three modes to define the number value that is compared if it is in range:

* **Variable** will allow you to define an existing variable to modify the number. This variable can be modified elsewhere using the **Roll a Random Number, Add/Subtract number** or **Set number value** Rules. A dropdown menu will appear to select a variable.
* **Fix value** will allow you to set up a constant value. An input field will appear to enter the number value.
* **Message Argument** will allow you to use an argument sent within the message. The message has to be created with an argument of the number type for it to be selectable here. A dropdown menu will appear to select the message argument.

**Comparison duration**&#x20;

With this checkbox ticked the condition will not only be checked when the Rule is activated but will wait until the condition is met and sent the **outgoing message.**

**Message to send**&#x20;

The outgoing message that is sent when the condition is met.
{% endtab %}
{% endtabs %}


---

# 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.sandbox.game/en/creator/game-maker/docs/game-rules/comparisons.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.
