# Replace Variable Values

## Use Cases:

* Loot systems
* Turn-based battle systems
* Memory-based puzzle games
* Upgrading outcomes with a random chance to obtain rare items
* Spawning rare monsters, equipment, bosses, quests, events
* Providing different outcomes for the same quest
* Lockouts
* Puzzles

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

## Edit Number Value

{% tabs %}
{% tab title="About" %}
Use the **Set Number** Rule to simply set a number variable to a new value. This can be used to reset a value to 0.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FUeuFuCDkwib4TyG72JBa%2Fimage.png?alt=media&#x26;token=c00f4c74-7c6d-4563-b2f0-06d76600a0ed" alt="" width="375"><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**

This is the number variable, that will be changed.

**New number value**&#x20;

There are three modes to define the value the selected variable will be set to:

* **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.
  {% endtab %}
  {% endtabs %}

## Edit True/False Value

{% tabs %}
{% tab title="About" %}
The **Set True/False** allows creators to change a Bool from True to False or from False to True. This could be useful when trying to adjust the visibility of the Rules UI.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FhYd4bYWs3q9aG9PMAmZL%2Fimage.png?alt=media&#x26;token=24e9ca35-31cf-49e0-9b84-86590038e41a" alt="" width="375"><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.

**True/False variable**&#x20;

This defines the **true/false** **variable** that is modified by this rule.

**New true/false variable**&#x20;

There are three modes to define the new value of the true/false variable:

* **Variable** will allow you to define an existing variable to modify the number. This variable can be modified elsewhere using the **Set true/false value** Rule. A dropdown menu will appear to select a variable.
* **Fix value** will allow you to set up a constant value. A checkbox will appear to toggle the 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 true/false type for it to be selectable here. A dropdown menu will appear to select the message argument.
  {% endtab %}
  {% endtabs %}

## Edit Text Value

{% tabs %}
{% tab title="About" %}
The **Set Text value** Rule allows creators to change text variables based on an incoming message. This can be used to reuse a variable for different banners, or show quest like messages in the UI.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FW3SQscAOetojbFDxpNFP%2Fimage.png?alt=media&#x26;token=4e32c613-6a14-488b-a092-ac00cb0446cf" alt="" width="375"><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.

**Text Variable**&#x20;

This defines the **text variable** that is modified by this rule.

**New Text**&#x20;

There are three modes to define the new text value:

* **Variable** will allow you to define an existing variable to modify the text. This variable can be modified elsewhere using the **Set text 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 text.
* **Message Argument** will allow you to use an argument sent within the message. The message has to be created with an argument of the text type for it to be selectable here. A dropdown menu will appear to select the message argument.
  {% endtab %}
  {% endtabs %}

## Store Player Name

{% tabs %}
{% tab title="Set Player Name" %}
This rule replaces the value of the text variable with the username of the player that triggered the rule.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FsnB8NUE2te5wzXe9vCbO%2Fimage.png?alt=media&#x26;token=ebf6cf24-8a30-48e0-9854-5f9084caaa18" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Details" %}

#### Required Message

Select the incoming message to trigger the rule.

#### Text Variable

Select the text variable that you want to change.
{% endtab %}
{% endtabs %}

## Roll a Random Number

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

#### **Create more variety and surprising experiences with random numbers!**

The **Choose Random Number** Rule is a quick and accessible way to create random numbers. It is possible to define the range in which the number will lie and send a message after the value is applied to a variable. This allows creators to create random based events, like enemy spawns or opening paths in a maze or simple dice rolls.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FTggnE5P7NErbOW6lL6kR%2Fimage.png?alt=media&#x26;token=f2e671eb-d8e6-4594-b377-f73513d65e08" alt="" width="375"><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 number that can be rolled:

* **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 number that can be rolled:

* **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**&#x20;

This defines the **number variable** that is modified by this rule.

**Message to send**&#x20;

This message is sent after the value is modified.
{% 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/replace-variable-values.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.
