# Game Rules

{% hint style="warning" %}
**NEW GAME MAKER 0.12 INFO COMING SOON!**\
The new release has a lot of amazing features, some of which impact the details on this page. Check back soon for an update, and in the meantime you can see a summary of all the updates in the [Changelog](https://docs.sandbox.game/en/creator/game-maker/version-notes-and-changelogs/game-maker-0.12).
{% endhint %}

{% embed url="<https://youtu.be/t-RF-DcoRcc>" %}

## About

The Game Rules system empowers builders to:

* Build logic more efficiently for greater game performance
* Design new gameplays and compelling mechanics: [tower-defense](https://docs.sandbox.game/en/creator/game-maker/creative-guides/experience-guide/tower-defense "mention"), [horror-backrooms](https://docs.sandbox.game/en/creator/game-maker/creative-guides/experience-guide/horror-backrooms "mention"), [resource-management](https://docs.sandbox.game/en/creator/game-maker/creative-guides/experience-guide/resource-management "mention"), [cooking-simulator](https://docs.sandbox.game/en/creator/game-maker/creative-guides/experience-guide/cooking-simulator "mention"), [survival](https://docs.sandbox.game/en/creator/game-maker/creative-guides/experience-guide/survival "mention"), and more!
* Enhance the functionality of object logic (behaviours and components)
* Guide players better and add game polish

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-type="content-ref"></th><th data-type="content-ref"></th><th data-type="content-ref"></th><th data-type="content-ref"></th><th data-type="content-ref"></th><th data-type="content-ref"></th><th data-type="content-ref"></th></tr></thead><tbody><tr><td>Rule types:</td><td><a href="game-rules/math">math</a></td><td><a href="game-rules/time">time</a></td><td><a href="game-rules/comparisons">comparisons</a></td><td><a href="game-rules/replace-variable-values">replace-variable-values</a></td><td><a href="game-rules/game-screen">game-screen</a></td><td><a href="game-rules/triggers">triggers</a></td><td><a href="game-rules/events">events</a></td></tr><tr><td>Variable use, presets, and templates to learn more:</td><td><a href="../creative-guides/game-rules-guide">game-rules-guide</a></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tbody></table>

***

## The Game Rules System

:new: [#using-multiple-gridboards](#using-multiple-gridboards "mention") and [#connectors](#connectors "mention")

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

### What is it?

The **Game Rules** system is a visual scripting tool in the [**Gameplay**](https://docs.sandbox.game/en/creator/game-maker/docs/build-menus/top-bar/gameplay) menu.&#x20;

It allows you to use and manipulate values such as **numbers**, **text**, **time**, and **true/false** values.

<table data-card-size="large" data-view="cards"><thead><tr><th></th></tr></thead><tbody><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="1f503">🔃</span> Store, modify, and reuse variables</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="2696">⚖️</span> Compare values</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="1f3b2">🎲</span> Generate random numbers</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="23f1">⏱️</span> Create timers and stopwatches</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> Display information in the player's <a data-footnote-ref href="#user-content-fn-1"><strong>HUD</strong></a>, popup windows, and banners</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="2328">⌨️</span> Trigger logic with key or mouse inputs and player entry/exit</td></tr></tbody></table>

### What Can I Make?

Create <mark style="background-color:blue;">**custom**</mark> mechanics, or use predefined game mechanics called <mark style="background-color:blue;">**Presets**</mark>:

[Collect Points](https://docs.sandbox.game/en/creator/game-maker/creative-guides/game-rules-guide/collect-points)    |    [Time Trial](https://docs.sandbox.game/en/creator/game-maker/creative-guides/game-rules-guide/time-trial)    |    [Point Race](https://docs.sandbox.game/en/creator/game-maker/creative-guides/game-rules-guide/point-race)    |    [Combo](https://docs.sandbox.game/en/creator/game-maker/creative-guides/game-rules-guide/combo)    |    [Hunger](https://docs.sandbox.game/en/creator/game-maker/creative-guides/game-rules-guide/hunger)    |    [Poison](https://docs.sandbox.game/en/creator/game-maker/creative-guides/game-rules-guide/poison)    |    [Shop](https://docs.sandbox.game/en/creator/game-maker/creative-guides/game-rules-guide/shop)
{% endtab %}

{% tab title="How it Works" %}

### How Does it Work?

The **Game Rules** system defines, tracks, and relays an Experience's **global mechanics**.

<table data-view="cards" data-full-width="false"><thead><tr><th></th></tr></thead><tbody><tr><td><p><strong>DEFINE</strong><br><br>Create <strong>Rulesets</strong> made of one or more <strong>Rules</strong></p><p></p><p>A <strong>Rule</strong> carries out actions, which may use <strong>variables</strong> you define and <strong>values</strong> you enter</p></td></tr><tr><td><strong>TRACK</strong><br><br>Changes to <strong>variables</strong> caused by <strong>Rule</strong> actions are stored for reuse<br><br><strong>Player variables</strong> <strong>(P)</strong> - track individual players<br><br><strong>Global variables (G)</strong> - track all players<br><br><strong>Team variables (T)</strong> - track teams (set in Spawn Point behavior)</td></tr><tr><td><p><strong>RELAY</strong><br><br><strong>Rules</strong> are trigged by messages <strong>In</strong> and send messages <strong>Out</strong> to communicate with:</p><ul><li>other <strong>rules</strong></li><li><strong>behaviours</strong> and <strong>components</strong> <br>(object logic)</li><li><strong>quests</strong> (Objectives)</li></ul></td></tr></tbody></table>

{% hint style="success" %}
**MULTIPLAYER GAMES**

Use a combination of **player variables (P),** **global variables (G)**, and **team variables (T)** depending on how you want **Rulesets** to be triggered, variables to be tracked, and information to be displayed in your game mechanics.
{% endhint %}
{% endtab %}

{% tab title="Game Rules Window" %}

### The Game Rules Window

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FZbUMOyBxqf9sNQUoJXIL%2Fimage.png?alt=media&#x26;token=99d427c1-7083-4240-9a38-5ebc6f75ce65" alt=""><figcaption><p>Game Rules in the Gameplay Menu. The Island Menu in the Game Rules window is highlighted on the left.</p></figcaption></figure>

:one: **Boards** button - opens a menu to select a gridboard or add a new one to organize rulesets.

:two: **Rules Guide** button - links to this documentation in the Creator Portal.

:three: **Rule Connectors** toggle - see chains of logic with messages sent/received in a gridboard.

:four: **Island Menu** - contains **Presets**, **Rules**, and **Variables** to build mechanics

:five: **Gridboard** - a space to add rules from the **Island Menu** and organise them into **Rulesets.**

:six: **Rules Hierarchy** dropdown (applies to the selected gridboard):

* view and duplicate rules
* focus on (go to) a rule or ruleset
* enable/disable [**debugging**](https://docs.sandbox.game/en/creator/game-maker/build-menus/top-bar#debug) for one or more rules or rulesets
  {% endtab %}

{% tab title="Controls" %}

### Controls

<table data-card-size="large" data-view="cards"><thead><tr><th></th></tr></thead><tbody><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span> <strong>OPEN GAME RULES</strong><br><br>Game Rules tab in the <a href="build-menus/top-bar/gameplay"><strong>Gameplay</strong></a> menu</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="274e">❎</span> <strong>CLOSE GAME RULES</strong><br><br>Click the <strong>X</strong> (top right)</td></tr><tr><td><p><span data-gb-custom-inline data-tag="emoji" data-code="1f532">🔲</span> <strong>MAX/MIN WINDOW</strong> (top right)</p><ul><li><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fv3DhXWXQcwnbeL9XmoFY%2Fimage.png?alt=media&#x26;token=fc3a4377-8d57-4c56-ab7b-c19bae527424" alt=""> Maximise</li><li><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FnHLqh3OxQJ34nhaEPM7g%2Fimage.png?alt=media&#x26;token=6ecb68bd-5937-4131-9832-609d755ca838" alt=""> Minimise</li></ul></td></tr><tr><td><p><span data-gb-custom-inline data-tag="emoji" data-code="1f50d">🔍</span> <strong>ZOOM IN/OUT</strong></p><ul><li>Click the magnify lenses (top right)</li><li><strong><code>CTRL</code> +</strong> <span data-gb-custom-inline data-tag="emoji" data-code="1f5b1">🖱️</span>move scroll wheel </li></ul></td></tr><tr><td><p><span data-gb-custom-inline data-tag="emoji" data-code="2195">↕️</span><span data-gb-custom-inline data-tag="emoji" data-code="2194">↔️</span> <strong>PAN GRID BOARD</strong></p><ul><li>Click and hold <span data-gb-custom-inline data-tag="emoji" data-code="1f5b1">🖱️</span> scroll wheel</li><li><strong><code>CTRL</code>+<code>WASD</code></strong> keys</li></ul></td></tr><tr><td><p><span data-gb-custom-inline data-tag="emoji" data-code="21a9">↩️</span><span data-gb-custom-inline data-tag="emoji" data-code="21aa">↪️</span> <strong>UNDO/REDO</strong></p><ul><li><strong><code>CTRL</code>+<code>Z</code></strong> - Undo</li><li><strong><code>CTRL</code>+<code>Y</code></strong> - Redo</li></ul></td></tr><tr><td><p><span data-gb-custom-inline data-tag="emoji" data-code="1f4cb">📋</span><span data-gb-custom-inline data-tag="emoji" data-code="2795">➕</span> <strong>COPY/PASTE</strong></p><ul><li><strong><code>CTRL</code> + <code>C</code></strong></li><li><strong><code>CTRL</code> + <code>V</code></strong><br><br><strong>Tip:</strong> Paste into a notepad to save/share (JSON format). <br>Pasting into an Experience generates included variables and messages.</li></ul></td></tr></tbody></table>
{% endtab %}

{% tab title="Multiple Gridboards" %}

### Using Multiple Gridboards

Game Maker 0.11 introduces multiple gridboards to organize rulesets.

* Add gridboard or category - Add button
* Select a gridboard - double click its name
* Rename/move - right click
* Delete - trash icon (press **`CTRL`+`Z`** to undo)
  * deleting a gridboard removes all of its rules
  * deleting a category removes all of its gridboards and rules
* Close **Boards** panel - click the X in the top right

{% hint style="info" %}
**Connectors** and **Rules Hierarchy** are unique to the selected gridboard. Rules on different gridboards communicate.
{% endhint %}

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FMzkpnLLaETzibfPU4cli%2FGM%20rules%20gridboards%200.11.png?alt=media&#x26;token=a35737e5-3347-4ef2-8ada-2f69431276e5" alt=""><figcaption><p>Example: Gridboards that may be useful to organize rules for a resource management game with enemy waves at night.</p></figcaption></figure>
{% endtab %}

{% tab title="Visualise with Connections" %}

### Connections

Toggle on connections to visualize how rules in a gridboard communicate with each other with their messages in and out. It's a helpful tool to quickly view how your rules logic will trigger.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FEy3ctqrA5mhX6bAsgG7s%2FGM%200.11%20Rule%20Connectors%20example%20crop.png?alt=media&#x26;token=05ce955d-b3e3-4101-aef0-37fbae54120e" alt=""><figcaption><p>Rule connectors show where messages are sent and received in a gridboard</p></figcaption></figure>

{% hint style="info" %}
Connections only apply to the selected gridboard, but rules on different gridboards will communicate with each other.
{% endhint %}
{% endtab %}
{% endtabs %}

## ![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FPAoet4rPdfcmDVq6mxct%2Fimage.png?alt=media\&token=09940638-d3de-41af-8246-82aada04aa3c) Rules

Rules are a sequence of steps carried out from top to bottom that can be reused in your game.

They offer new possibilities, mechanics, and shortcuts to solve complex problems.

{% hint style="info" %}
Game Rules will only receive a message from objects if the **Broadcast Type** is *All* or *Rules*.
{% endhint %}

{% hint style="info" %}
To decrease a variable, use a negative number in the value change logic box.
{% endhint %}

{% tabs %}
{% tab title="Rule Types" %}

### Rule Types

<table data-view="cards"><thead><tr><th data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="game-rules/math">math</a></td></tr><tr><td><a href="game-rules/time">time</a></td></tr><tr><td><a href="game-rules/comparisons">comparisons</a></td></tr><tr><td><a href="game-rules/replace-variable-values">replace-variable-values</a></td></tr><tr><td><a href="game-rules/game-screen">game-screen</a></td></tr><tr><td><a href="game-rules/triggers">triggers</a></td></tr><tr><td><a href="game-rules/events">events</a></td></tr></tbody></table>

Click a rule type to expand the list of options. Click on a rule in the list to add it to a gridboard.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FGiTo6CDrIwAQsasFhZG7%2FGM%20rules%20menu%200.11.png?alt=media&#x26;token=802f8302-8b37-48fe-9984-659f31a76b7e" alt=""><figcaption><p>Shown: <strong>Math</strong> rule added to a new ruleset</p></figcaption></figure>
{% endtab %}

{% tab title="Logic Boxes: Logical Flow" %}
{% hint style="warning" %}
Logic boxes highlighted in red require more information to make the rule active.
{% endhint %}

### A Rule's Logical Flow

**Logic boxes** break down Rules into simple steps executed from top to bottom:

1. **Trigger**\
   A rule is triggered by a message **In**.\
   If a **message with arguments** is received, the argument value may be used in a rule's action.\
   ![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fe8RBiuq2zsVoDYErarm8%2Fimage.png?alt=media\&token=c31f37c4-7515-41ed-aa15-df10c1b79856)<br>
2. **Variable(s)**\
   A rule may use zero, one, or multiple stored values defined by name and type.\
   ![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FK0soGPIs7MS2nzNSwIDT%2Fimage.png?alt=media\&token=82297e2e-9700-44da-ba24-2199828a62c1)<br>
3. **Action(s)**\
   An action to carry out (e.g., change a variable, compare values, display on the HUD, etc).\
   ![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FlBgSov19cYvqVHxvv2Xm%2Fimage.png?alt=media\&token=28944ac9-4763-46a4-91eb-619fe7e41a96)<br>
4. **Message to Stop the Rule**\
   Some rules allow another message **In** to stop its actions.\
   ![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fs1Ghir4nikuoJFb7QvgS%2Fimage.png?alt=media\&token=f3dab8da-3968-4b91-b6d3-e8fd7e8e315d)<br>
5. **Output**\
   An optional message **Out** may trigger another rule, object logic, or quest.\
   A **message with arguments** may be sent for more complex logic or fewer rules.\
   ![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FBydRoWUKY3mIxm40mZ7f%2Fimage.png?alt=media\&token=7313b370-c1f8-46a5-b27e-a782c4dad5e8)

**EXAMPLE**

**Timer Rule**

<table data-card-size="large" data-view="cards"><thead><tr><th></th></tr></thead><tbody><tr><td><p><strong>Player Perspective</strong><br>Enter an area. A timer appears as a door opens, indicating limited time to enter.<br><br>Re-enter the area to start a timer again.</p><p><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FtI6ai8RYwkqgOliRc7x3%2FGM%20Rules%20TimerShowcase.gif?alt=media&#x26;token=8553e312-30f2-4d42-9ea6-46b6e929b61a" alt="Example: Timer" data-size="original"></p></td></tr><tr><td><p><strong>Logic Flow of the Timer Rule</strong></p><ul><li><strong>Trigger -</strong> When the player enters an area and is detected, a message is sent to the Rule.</li><li><strong>Variable -</strong> A time variable will be used to store the timer.</li><li><strong>Actions -</strong> The timer is displayed and starts to count down.</li><li><strong>Output -</strong> When the timer reaches 0, a message is sent to close the door.<br><br>The timer can be reused if triggered.</li></ul></td></tr></tbody></table>
{% endtab %}

{% tab title="Trigger a Rule" %}

### Trigger a Rule

A rule is triggered by a message received. This can be done in many ways. Here are just a few ideas:

* Collect, destroy, spawn, or interact with objects
* Use a [**Message Broadcaster**](https://docs.sandbox.game/en/creator/game-maker/docs/behaviours/basic-logic/message-broadcaster) to send messages repeatedly with a delay between
* Use [**Timed Events**](https://docs.sandbox.game/en/creator/game-maker/docs/behaviours/basic-logic/timed-events) to send a message in a sequence a sequence of events
* Use an outgoing message sent from a rule to trigger a different rule
  {% endtab %}

{% tab title="More Rule Info" %}

### More Rule Info

<img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FFh11itlSaHdlzIUgbylV%2Fimage.png?alt=media&#x26;token=be286e48-4fc2-4957-a907-f57e4e4fe833" alt="" data-size="original"> Right click a Rule and use :arrow\_up\_small::arrow\_down\_small: arrows to view details about each **logic box**.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FUEgWybJmrXUj3I1Sxa6U%2Fimage.png?alt=media&#x26;token=726a09df-370b-4314-8296-49d62f1fa8a5" alt=""><figcaption><p>Rule Info mode</p></figcaption></figure>
{% endtab %}
{% endtabs %}

## ![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FsOwdeEBDHxkgn00zS9O4%2Fimage.png?alt=media\&token=bbfeb93a-c8ce-49b8-b68b-7c14fe39ed35) Variables

:new: [Team Variable](#how-variables-are-applied) and [#multiplayer-use-cases-for-variables](https://docs.sandbox.game/en/creator/creative-guides/game-rules-guide#multiplayer-use-cases-for-variables "mention")

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

### What Are Variables?

Variables are the backbone of the Game Rules system. Almost every rule can or must work in combination with a variable.

They can be used to store information to build more complex logical systems and provide important information to players.

#### Create or Repurpose

Variables are automatically created when you use a **Preset** in **Game Rules** (more information below) or if you paste a ruleset into a gridboard. You can also create any type of variable you want and change the variable used in a rule.

{% hint style="warning" %}
A variable can be renamed and its value can be changed, but it can not be modified to a different type or be applied differently.

Create the type of variable needed and how it will be applied, replace the old variable in a rule, and delete the old variable.
{% endhint %}
{% endtab %}

{% tab title="Variable Types" %}

### Variable Types

Currently the following types of variables are available:

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="1f522">🔢</span> <strong>Number</strong> - Integers (e.g., 255)</td><td>Whole numbers for counting resources, scores, etc.</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="1f9ee">🧮</span> <strong>Decimal Number</strong> (Float e.g., 2.55)</td><td>Non-whole numbers for more precise calculations (currency, using division, etc).</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="1f524">🔤</span> <strong>Text</strong> - Short character strings</td><td>Display short text in banners or HUD slots (status, location, player name/level, etc).</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="23f1">⏱️</span> <strong>Time</strong> - Time values</td><td>Timers and stopwatches that can be stopped, paused, and resumed.</td></tr><tr><td><span data-gb-custom-inline data-tag="emoji" data-code="262f">☯️</span> <strong>True/False</strong> - Boolean (binary) values</td><td>Set a state to manage logic, with potential to create <strong>if/else</strong> structures.</td></tr></tbody></table>
{% endtab %}

{% tab title="Player, Team & Global" %}

### How Variables are Applied

{% hint style="info" %}
**Local** variables have been renamed to **player** variables in Game Maker 0.11.
{% endhint %}

A variable can be applied three ways: **global**, **player**, or **team**.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FCFGGxhu3PVs3IrxGS2Yx%2Fimage.png?alt=media&#x26;token=b82fe3a3-703d-4e21-b346-239a34a4eb4a" alt="" width="305"><figcaption></figcaption></figure>

<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Global (G)</strong></td><td>Synchronised values for all players</td><td><strong>Example:</strong> <br>All players earn a resource anyone can use.</td></tr><tr><td><strong>Player (P)</strong></td><td>Store each player's values based on their individual actions</td><td><strong>Example:</strong> <br>Each player earns different resources to use their own way.</td></tr><tr><td><strong>Team (T)</strong></td><td>Stores values based on the actions of members of each team</td><td><strong>Example:</strong><br>Team members work together to earn a resource to gain a competitive edge over other teams.</td></tr></tbody></table>

### Player & Team Variable Data

{% hint style="warning" %}
Player interaction is required to trigger changes to a **player** or **team** variable.
{% endhint %}

**Player Source**

To modify a variable for the correct player or team during play, an interaction from a player must trigger a message that will then include **player source** data.&#x20;

{% hint style="info" %}
In Game Maker 0.11, a player source is also needed to correctly trigger Objectives in multiplayer Experiences.
{% endhint %}

**Examples:**

* detection by a [speaker](https://docs.sandbox.game/en/creator/game-maker/docs/components/actions/speaker "mention") or [trigger-volume](https://docs.sandbox.game/en/creator/game-maker/docs/components/triggers/trigger-volume "mention")
* answering a question via [asker](https://docs.sandbox.game/en/creator/game-maker/docs/behaviours/basic-logic/asker "mention")
* pressing a [button](https://docs.sandbox.game/en/creator/game-maker/docs/components/triggers/button "mention")
* and more

{% hint style="info" %}
**ABOUT TEAMS**

* Teams are assigned via [**Spawn Point**](https://docs.sandbox.game/en/creator/game-maker/docs/behaviours/basic-logic/spawn-point-and-avatars-feature) behavior.
* Behaviours, components, and the **Send Message** rule can broadcast a message to a specific team.
  {% endhint %}
  {% endtab %}

{% tab title="Variables Window" %}

### Variables Window

The **Variables** window lists all variables in the Experience. Each will have a tag of either **G**, **P**, or **T** to show whether they are **global**, **player**, or **team variables**.

In this area new **variables** can be **added** and existing ones can be **removed** or **edited**. The list shows the variables' **names**, whether they are **global**, **player**, or **team** variables, and **type** (number, decimal number, time, true/false and text).&#x20;

Enter the name for internal use in the **Name**<mark style="color:red;">**\***</mark> field. You will create a custom name to appear in the player's **HUD**, or Heads-Up Display, in the [Broken link](https://docs.sandbox.game/en/creator/game-maker/docs/broken-reference "mention") rule.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FpTQJNOzxvKjgs222PFfZ%2Fimage.png?alt=media&#x26;token=9a6a7860-ad4c-4afc-a57b-387628157815" alt="" width="304"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Use Variables" %}

### Rules

To use a variable in a rule, add the rule and click **Select Variable** (if a variable is not selected yet, the logic box will be red and the rule will not be active).

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FHaoo2s5p4c2gr4264byH%2Fimage.png?alt=media&#x26;token=47cc3183-d392-4952-a1bb-cf7f527cf30b" alt="" width="266"><figcaption></figcaption></figure>

The **Variables** window will open on the left. Check the box next to the variable you want to use.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FD76fPbfpnMbx5bjEJQQ9%2Fimage.png?alt=media&#x26;token=9693a477-2358-4637-8518-5ae9029a294f" alt="" width="563"><figcaption></figcaption></figure>

For a **Team** variable, you can choose **Triggering Team** or a specific team name (which is created via [**Spawn Point** ](https://docs.sandbox.game/en/creator/game-maker/docs/behaviours/basic-logic/spawn-point-and-avatars-feature)behavior).

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FpzjK3ga6fS2vmLxRijxb%2Fimage.png?alt=media&#x26;token=4123bb05-8bcf-4d86-b246-75a0afb75518" alt="" width="350"><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## Rulesets

**Rulesets** are a way to visually organise a group of rules used for the same game mechanic.

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

### How Rules Act in a Ruleset

Rules may be grouped into a Ruleset, but **they still act independently** when triggered:

* The order in which rules are placed in a ruleset does not change the flow of logic.
* A rule's message **Out** may trigger another rule in the same ruleset or in a different one.
* Some rules may not send a message **Out**.
* a rule may trigger another rule in a different gridboard.

**Example**

The **Collect Points** ruleset (a **Preset**) is a gameplay mechanic that includes a chain of two rules (shown in red below) and other rules that act independently of the others.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FEWmkQ5zkkDp8GLz1yVoM%2FGM%20ruleset%20collect%20points%200.11.png?alt=media&#x26;token=8226692e-a4d2-49f5-b93a-6ae82815e97e" alt=""><figcaption><p>Example: Collect Points ruleset (a Preset) - click to expand</p></figcaption></figure>
{% endtab %}

{% tab title="Managing Rules and Rulesets" %}

### Managing Rules and Rulesets

<table data-view="cards"><thead><tr><th></th></tr></thead><tbody><tr><td><p><strong>Add a Rule</strong><br>- <strong>To a new ruleset</strong></p><ul><li>Click on a rule in the Rules list</li></ul><p><strong>- To an existing ruleset</strong></p><ul><li>Select a ruleset to add it to, then click on a rule in the Rules list</li><li>Click the <span data-gb-custom-inline data-tag="emoji" data-code="2795">➕</span> button next the the name of the ruleset</li></ul></td></tr><tr><td><p><strong>Rename, Duplicate, or Delete a ruleset</strong><br><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FstYCYeItW4yTPw0pv2hc%2Fimage.png?alt=media&#x26;token=bc796977-b42b-400e-a3ad-390f2d1a70f7" alt="" data-size="original"></p><ul><li>Select a ruleset to reveal a small menu of buttons (top center)</li></ul></td></tr><tr><td><p><strong>Move a rule to a ruleset</strong></p><ul><li>Drag a rule from the gridboard or another ruleset into the desired ruleset with the ⠿ grabber at the top right of a rule</li></ul></td></tr></tbody></table>

### Move a Ruleset to a Different Gridboard

Use `CTRL`+`C` to copy a ruleset and `CTRL`+`V` to paste a ruleset into a different gridboard. Then delete the ruleset from the old gridboard.
{% endtab %}
{% endtabs %}

### ![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FVPbZ1ggAARWvUypYIrgP%2Fimage.png?alt=media\&token=c782fbc0-86ba-4a23-a21c-172e2b3ed033) Presets

**Presets** are pre-built **rulesets** you add to a gridboard with a single click. This is a fast way to set up commonly used game mechanics and customise as needed.

When adding a Preset, **all necessary variables and messages are automatically generated**.

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

### Add then Integrate

Presets are accessed with a button in the **Island Menu** on the left. Click on a Preset in the list to add it to a selected gridboard.

Customise messages sent/received, variables used, rule names, and more as needed.&#x20;

Integrate the Preset to communicate with your object logic (behaviours and components) to activate the Preset's mechanics in your Experience.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fn0S8TYZ11TBzbGt7iR23%2Fimage.png?alt=media&#x26;token=c359beec-d907-4cdc-a48b-6965defc808c" alt="" width="463"><figcaption><p>Game Rules - Presets</p></figcaption></figure>
{% endtab %}

{% tab title="Apply a Preset" %}
{% hint style="success" %}
**STEP-BY-STEP EXAMPLE: APPLY A PRESET**

Visit the Game Rules Guide's [**Collect Points page**](https://docs.sandbox.game/en/creator/game-maker/creative-guides/game-rules-guide/collect-points) for a full step-by-step example of how to apply a Preset to your Experience logic.
{% endhint %}

### Integrate a Preset with Your Experience

#### Check Variables Included

Review variables created with your Preset to make sure they are **player** (**P**) for individual players, **global** (**G**) for all players, or **team** (T) for teams, depending on how you want them to apply.

#### Set up Messages to Trigger the Rules Included

Modify messages sent by objects or messages required in the preset's rules to ensure they will communicate as expected.

There are multiple ways to send a message. Here are a few examples:

* Collect, destroy, spawn, or interact with objects
* Use a Message Broadcaster to send messages repeatedly with a delay between
* Use Timed Events to send a message in a sequence a sequence of events
* Use an outgoing message in another Rule to trigger a different one

{% hint style="info" %}
Make sure a message is being sent to rules through direct player interaction for player or team variables to be affected correctly with [**player source data**](#how-variables-are-applied).
{% endhint %}

#### Debug

If your mechanic isn't working as expected, you can [**debug specific rules or rulesets**](https://docs.sandbox.game/en/creator/game-maker/build-menus/top-bar#rules-logger-1).
{% endtab %}
{% endtabs %}

## Export and Import Rulesets

Copy and paste Rulesets with **`CTRL`+`C`** and **`CTRL`+`V`**. Messages and variables are included!

* Paste generated text into external sources like a notepad to share.
* Paste into other Experiences to reuse your Ruleset!

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F94prWv9PZxjqfKKvtY4d%2FGM%20Rules%20Export%20Import%20sm%20opt.gif?alt=media&#x26;token=45766112-2e70-4ab2-b29f-ada38701de60" alt=""><figcaption><p>Copy &#x26; Paste Rulesets</p></figcaption></figure>

## :new: Multiplayer Ranking

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td></td><td></td><td></td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F4aH1GJc62gjQgf7yL24v%2Ftrophy%20graphic.png?alt=media&#x26;token=874ccf99-aa9a-4cb0-8798-f23b53fb575e">trophy graphic.png</a></td></tr><tr><td>Experience creators may set up two types of ranking data for players to view:</td><td><strong>Local Ranking -</strong> Current play session data</td><td><strong>Global Ranking -</strong> All play session data</td><td></td></tr></tbody></table>

{% hint style="warning" %}
A multiplayer Experience must be published to the map or shared to the gallery to view Ranking data during play or on the website.
{% endhint %}

{% hint style="warning" %}
**NO DATE FILTER FOR GLOBAL RANKINGS... YET!**\
Take a snapshot of global rankings at the end of your events for accurate data.
{% endhint %}

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

### How Ranking is Determined

* **Numeric variables** (Number, Decimal Number, Time) can be used to create player rankings.
* **Up to three variables** can be used to sort player ranking data.
* **Sorting** can be done in **ascending** or **descending** order per variable.

### How Ranking Data is Displayed

#### Game Client / Game Maker Gallery

1. Victory/Defeat screen is triggered
2. Local Ranking screen appears
3. Global Ranking screen appears

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F3KsDisiw0oiYPIU8CRPB%2FGM%200.11%20Rules%20System%20Rankings.png?alt=media&#x26;token=3f8a0987-6801-4d57-aa0b-fed7a0042965" alt="" width="563"><figcaption><p>Ranking Screen (Game Client / Game Maker Gallery)</p></figcaption></figure>

#### [experience-page](https://docs.sandbox.game/en/creator/game-maker/publish-experiences/experience-manager/experience-page "mention")

Global Ranking data updates in real time as Local Ranking data is collected from play sessions.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fo1707GSpejh4s71iKcHW%2Fimage.png?alt=media&#x26;token=3733247f-992a-4024-a540-5029ca4587aa" alt="" width="563"><figcaption><p>Experience Page Ranking Tab (Top 100)</p></figcaption></figure>
{% endtab %}

{% tab title="About Global Ranking" %}

### Global Ranking

* Automatically displays on the Experience Page in a Ranking tab
* Can be reset when updating the Experience, or at any time
* Data updates in real time
* Displays up to 100 top players based on criteria set in Game Maker

{% hint style="info" %}
For the first version of this feature, Global Ranking data cannot be exported.
{% endhint %}

{% hint style="warning" %}
For the first version of this feature, there is **no date filter** to view rankings.&#x20;

If you are running a contest that requires Global Ranking data, visit your Experience Page and take a "snapshot" of data at the right day/time for fair and accurate data.
{% endhint %}
{% endtab %}

{% tab title="Ranking Settings" %}

### Ranking Settings

1. Set a **Message to validate data**
2. Add up to three numeric **variables** to determine player rank
   1. Primary
   2. Secondary (tie breaker if Primary data is the same)
   3. Tertiary (tie breaker if Primary and Secondary data is the same)
3. Use controls to customise settings further

{% hint style="info" %}
Secondary and Tertiary variables can also provide interesting information for players.
{% endhint %}

#### Controls

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FTiuUKEJkMXOK7GBEosqh%2FGM%200.11%20Rules%20System%20window%20Rankings%20UI%20labeled.png?alt=media&#x26;token=ee498cc7-3189-4a1c-835c-61de7d2f8691" alt=""><figcaption></figcaption></figure>

1. **Ranking button** - Open Ranking screen
2. **Ranking screen**
3. **Message to validate data** - The message you enter here must be sent to Rules to capture variable data before victory/defeat triggered
4. **Add a variable** - If the plus sign does not appear, you need to create a number, decimal, or time variable to add
5. **Remove a variable**
6. **Variable title** - Click to edit how it will appear on Rankings screens and the Experience Page
7. **Sort variable values** - Ascending or descending
8. **Create a Global Ranking** - Display Ranking data for all play sessions on the Experience Page and at the end of each game session

{% hint style="info" %}
Change a variable's format (e.g., time as mm:ss) by editing it in the Variables screen.
{% endhint %}
{% endtab %}

{% tab title="Trigger a Ranking" %}

### Trigger a Ranking

#### (Optional) Time Variables

:pause\_button: If a **time variable** will be included in the ranking, it <mark style="background-color:orange;">must</mark> be started <mark style="background-color:orange;">and</mark> paused/stopped before data validation and victory are triggered

#### (Required) All Use Cases

:camera\_with\_flash: Trigger a snapshot of variable data (send a validation message to **Rules**)

![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FevP3vMACf4ExvtsLhzQU%2Fimage.png?alt=media\&token=542acf5c-8fb1-4f21-a6cc-4162a34aadba) Trigger a [victory](https://docs.sandbox.game/en/creator/game-maker/docs/components/gameplay/victory "mention") or [defeat](https://docs.sandbox.game/en/creator/game-maker/docs/components/gameplay/defeat "mention") component to end the game, revealing the ranking screen
{% endtab %}
{% endtabs %}

### Examples

{% tabs %}
{% tab title="Example: Team MVP" %}

### Example: Team Results & MVP

If you want to rank by team results and then by each player's data (e.g., highlight the MVP):

* Primary: Team variable
* Secondary: Player variable

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FWOxN0Oz7n2BvcFcHIIap%2Fimage.png?alt=media&#x26;token=315e66b1-1ee9-46b1-bacf-e07bcc1689c2" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Example: Timed Race" %}

### Example: Timed Race

{% hint style="info" %}
This is a workaround due to minor delays that may occur when messages are sent. Even with the same trigger (e.g., a Trigger Volume component), a player time variable will not start each player's value at the exact same time.
{% endhint %}

To <mark style="background-color:orange;">accurately</mark> collect each player's time data in a race with a global timer:

* Create a global time variable, trigger at the start of the race
* Create a player time variable, trigger with player interaction/detection to receive a player source
* At race start: Trigger the global time variable to begin
* When a player crosses the finish line: Pause the local variable and overwrite the value with a Set Time Value rule, using the global time variable's value in the rule
  {% endtab %}

{% tab title="Example: Survival Game" %}

### Example: Zombie Apocalypse Survival Game

A survival game may have Ranking set up in many ways depending on the goals of the game:

* Medium difficulty survival
  * Primary variable: Survival time (descending)
* High difficulty survival
  * Primary variable: Number of player deaths (ascending)
  * Secondary variable: Best survival time (descending)
* Save the world
  * Primary variable: People rescued
  * Secondary variable: Zombie kills
    {% endtab %}
    {% endtabs %}

[^1]: Heads Up Display - a user interface on the player's screen


---

# 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.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.
