# Build Singleplayer & Multiplayer Logic

## Game Maker's Logic Systems

<div><figure><img src="/files/kUOLSduLdkDnkd4JV4a6" alt="" width="360"><figcaption><p>Game Rules</p></figcaption></figure> <figure><img src="/files/YuRVTK4qcsBnMjTtVy8D" alt="" width="360"><figcaption><p>Objectives <br>(Quests)</p></figcaption></figure> <figure><img src="/files/uHVVc7yZ9zSLOCBIm0ln" alt="" width="361"><figcaption><p>Voxel Object Logic <br>(Behaviours &#x26; Components)</p></figcaption></figure> <figure><img src="/files/N4vfBHSs8AiAz00NORpL" alt="" width="375"><figcaption><p>Gameplay Parameters<br>(affects all players)</p></figcaption></figure></div>

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><a href="/pages/0QRji0ImFYbtgTbszoko"><strong>GAME RULES</strong></a></td><td><p>Rules are gameplay mechanics that can be triggered and completed repeatedly and use variables for all players or individual players.</p><p><br><strong>Example:</strong> <br>Points, Timers, Shops, and more</p></td></tr><tr><td><a href="/pages/J4ByurEhXfskskE6Uosc"><strong>OBJECTIVES</strong></a> <strong>(QUESTS)</strong></td><td><p>Quests are an individual player's progress in a singleplayer or multiplayer Experience's flow, which can be completed only one time.<br></p><p><strong>Example:</strong> <br>A quest to collect coins</p><p></p></td></tr><tr><td><strong>OBJECT LOGIC</strong></td><td><p><a href="/pages/UfuvOiV2urztB4lTDt2p"><strong>Behaviours</strong></a> &#x26; <a href="/pages/VonuKRJlsyZELqrtBj8t"><strong>components</strong></a> are logic applied to voxel objects placed in the game world.<br></p><p><strong>Example (image above):</strong></p><p>Light, NFT Sensor, NFT Image Display, Play Sound &#x26; Trigger Volume<br><br>This includes <a href="/pages/dwklrmeJJDt7o3yu7RlG"><strong>Spawn Point</strong></a> behavior, which includes unique settings per spawn point such as custom avatar, team assignment, equipment, tags, etc.</p></td></tr><tr><td><strong>Gameplay</strong> <a href="/pages/Aqp8LzUVw7V6eG2U7fuS#parameters"><strong>Parameters</strong></a></td><td><p>Global settings to customize basic interactions.<br></p><p><strong>Example:</strong></p><p>The player's avatar may be allowed to swim, breathe oxygen, receive fall damage, use abilitities, etc.</p></td></tr></tbody></table>

### Object Logic

{% tabs %}
{% tab title="Logic Layers" %}

### <mark style="color:green;">\[SP]</mark> & <mark style="color:yellow;">\[MP]</mark> Behaviours and Components

A split between <mark style="color:green;">**\[SP]**</mark> and <mark style="color:yellow;">**\[MP]**</mark> logic was introduced with Game Maker 0.8.&#x20;

This made it possible for players to experience some logic independently and other logic simultaneously with all other players. Synchronised logic includes position and state of objects, environment, global mechanics, etc.

An object may have **one** of the following logic setups:

<table data-view="cards"><thead><tr><th></th></tr></thead><tbody><tr><td><strong>No logic applied</strong></td></tr><tr><td><strong>Only </strong><mark style="color:green;"><strong>[SP]</strong></mark><strong> logic</strong><br><strong>"Client Only" -</strong> for each player to experience at different times<br><br><strong>Example:</strong> <br>A player explores gameplay at their own pace and reads Quest dialogue when ready</td></tr><tr><td><strong>Only</strong> <mark style="color:yellow;"><strong>[MP]</strong></mark><strong> logic</strong><br><strong>"Networked" -</strong> for all players to experience at the same time<br><br><strong>Example:</strong> <br>A door opening or a platform moving is synchronised for all players</td></tr></tbody></table>

{% hint style="info" %}
In [**Singleplayer Experiences**](#singleplayer-experiences), <mark style="color:yellow;">**\[MP]**</mark> logic works like <mark style="color:green;">**\[SP]**</mark> logic. Gameplay design is more simple.

In [**Multiplayer Experiences**](#multiplayer-experiences), there are communication and bandwidth limitations to consider when designing gameplay.
{% endhint %}
{% endtab %}

{% tab title="Selecting SP or MP" %}

### Selecting <mark style="color:green;">\[SP]</mark> or <mark style="color:yellow;">\[MP]</mark>

1. Select an object and click on the behaviour or component field in the Properties panel.
2. When the pop-up window opens, use the dropdown at the top right to select a logic **Type**: **All**, <mark style="color:green;">**\[SP]**</mark>**&#x20;Client Only**, or <mark style="color:yellow;">**\[MP]**</mark>**&#x20;Synchronised.**
3. Click on the desired logic for your needs, and it will be added to the selected object.

<figure><img src="https://4251931498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MO_j99BJEXK4zHqxgqS%2Fuploads%2F4BXkHtGKRaWTz16WFmfl%2FMP%20behaviours%20dropdown%20highlighted.png?alt=media&#x26;token=2049854a-a06e-409e-9da2-76ff384d8186" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="info" %}
There is no visual indicator in the viewport that an object has <mark style="color:green;">**\[SP]**</mark> or <mark style="color:yellow;">**\[MP]**</mark> logic. Select an object to view its properties.
{% endhint %}

{% hint style="info" %}
Game Maker will automatically grey out options you cannot apply.&#x20;

For example, <mark style="color:yellow;">**\[MP]**</mark> and <mark style="color:green;">**\[SP]**</mark> variants of behaviours and components cannot exist on the same object since they communicate on different layers.
{% endhint %}

{% hint style="info" %}
Remove all logic to switch an object to the other type.
{% endhint %}

<figure><img src="https://4251931498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MO_j99BJEXK4zHqxgqS%2Fuploads%2FggEYelcZPwx53sP6dV1M%2F%5BSP%5D%20%5BMP%5D%20Split_Compatability.gif?alt=media&#x26;token=6d5dd950-02fc-4eab-b3a8-f9c46074c16b" alt="" width="563"><figcaption><p>Trying to select a Behaviour or Component from an alternate network will result in the message:<br>"<em><strong>BLOCKED BY</strong> Network policy incompatible with another behaviour/component assigned to the actor/s.</em>"</p></figcaption></figure>

<figure><img src="https://4251931498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MO_j99BJEXK4zHqxgqS%2Fuploads%2F7kWhlNN19vvzNrfFX5ef%2FBehaviour%20Selection%20BLOCKED.JPG?alt=media&#x26;token=95b75fed-ba88-498b-abbb-2218d3080e95" alt="" width="563"><figcaption><p>The message received when trying to add a [SP] Component to an actor with a [MP] Behaviour.</p></figcaption></figure>
{% endtab %}
{% endtabs %}

## Triggering Logic Across Systems

![](/files/JMtrfm5HbYsCN4qAgNGB) [**Messages**](/en/creator/game-maker/docs/using-assets-and-objects/messages.md) are sent between and within systems to trigger gameplay logic.

Logic can be a simple or complex chains of events, and it can be linear or branching with options.

There are many simple ways to send a message and trigger something to happen. Messages can also be directed more specifically using [**filters**](/en/creator/game-maker/docs/using-assets-and-objects/behaviour-and-component-parameters.md#filtering-message-targets) and [**tags**](/en/creator/game-maker/docs/using-assets-and-objects/tags.md).

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

### Broadcast

Send a message on start of the Experience or when triggered, once or repeatedly.

**Example:**&#x20;

* Add a [**Message Broadcaster**](/en/creator/game-maker/docs/behaviours/basic-logic/message-broadcaster.md) behaviour to a logic actor or object and set desired parameters.

{% hint style="success" %}
Use a **message broadcaster** as a middle step if two logic elements will not send or receive messages as quickly, consistently, or specifically as you want.
{% endhint %}
{% endtab %}

{% tab title="Detect" %}

### **Object/Player Avatar Detection**

An object can send a message when an expected tag is detected. It can also be set to play one of its animations. Detection is triggered when:

* player avatars are in range
* specific tags are in range
* specific objects are in range

**Examples:**

* Add a [**Speaker**](/en/creator/game-maker/docs/components/actions/speaker.md) component and choose what to detect and detection range (avatars, tags, or a specific actor).
* To trigger an asset's animation and send a message when an avatar is detected or a message is received, use [**Animated Decoration**](/en/creator/game-maker/docs/behaviours/visual/animated-decoration.md) behaviour.
* The [**Trigger Volume**](/en/creator/game-maker/docs/components/triggers/trigger-volume.md) component can also detect and trigger a message when any tag enters or exits its volume.
  {% endtab %}

{% tab title="Destroy" %}

### **Object Destruction**

Send a message or drop (spawn) a new object (e.g. loot, smaller enemies, etc) when an object is destroyed from an attack or an instant kill message.

**Example (direct):**

* **Send Message** - Add a [**Health** ](/en/creator/game-maker/docs/components/status/health.md)component to the object that will be destroyed. Set a **Message sent on death**. You can trigger this with an **Instant death message**.

**Example (indirect):**

* **Drop (spawn) object** - Add a [**Drop**](/en/creator/game-maker/docs/components/actions/drop.md) component to the object that will be destroyed. Choose **Behavior** (default asset settings) or [**Preset** ](/en/creator/game-maker/docs/build-menus/side-bar/presets.md)(custom settings for one or more objects to spawn). Select the asset or preset to spawn.&#x20;
  * Other objects nearby with a [**Speaker**](/en/creator/game-maker/docs/components/actions/speaker.md) component can detect a tag that is included in your spawned object.
  * A spawned object, such as a [**Message Broadcaster**](/en/creator/game-maker/docs/behaviours/basic-logic/message-broadcaster.md), could instantly send a message.
    {% endtab %}

{% tab title="Collect" %}

### **Object Collection**

Can be set as collectible by one player or every player, send a message, and/or play a sound.

**Example:**

Add a [**Collectable** ](/en/creator/game-maker/docs/components/actions/collectable.md)component to an object and set a message to send.
{% endtab %}

{% tab title="Interact" %}

### **Object Interaction (E)**

Press E to send the “Interact” Message. This can trigger a wide variety of events depending on logic setup.

**Examples:**

* Open a door to access a new area
* Toggle on/off logic
* Talk to NPCs for a quest
* Collect or pick up an item
* View NFT info (The Sandbox & external NFTs)
* More complex logic sequences
  {% endtab %}

{% tab title="Quest" %}

### **Objectives/Quests**

Send a message after receiving confirmation that a quest condition is met and/or after the quest is complete.

**Example:**

* Create an [**Objective/Quest**](/en/creator/game-maker/docs/objectives.md). In the **Action After Completion** dropdown, choose **Send Message**. Use the dropdown below this to select an existing message or create a new one. Any object in your Experience will be able to receive this message.
  {% endtab %}

{% tab title="Rules" %}

### **Game Rules**

Most rules can optionally send a message when their logical flow is complete. Some may also be stopped or paused with a message.

**Example:**

* Add a rule to the gridboard, set the Message **In**, apply any custom settings you like, and set the Message **Out**. Trigger the Message **In** and the Message **Out** will quickly be sent.
  {% endtab %}
  {% endtabs %}

<figure><img src="/files/sR8z1cK6r2lWWMiOccAR" alt="" width="563"><figcaption></figcaption></figure>

## Creating Experiences

### :bust\_in\_silhouette: Singleplayer

{% tabs %}
{% tab title="1 Layer" %}

### One Layer of Logic

{% hint style="success" %}
**FULL DESIGN FLEXIBILITY**

:white\_check\_mark: <mark style="color:yellow;">**\[MP]**</mark> and <mark style="color:green;">**\[SP]**</mark> logic communicate with each other in singleplayer games.

:white\_check\_mark: <mark style="color:yellow;">**\[MP]**</mark> and <mark style="color:green;">**\[SP]**</mark> logic communicate with an individual player's **Objectives**/quests.

:white\_check\_mark: <mark style="color:yellow;">**\[MP]**</mark> and <mark style="color:green;">**\[SP]**</mark> logic communicate with **Game Rules**.
{% endhint %}
{% endtab %}

{% tab title="Fundamentals" %}
{% hint style="info" %} <mark style="color:green;">**\[SP]**</mark> means ***Client Only***, and <mark style="color:yellow;">**\[MP]**</mark> means ***Synchronised*** to all players. Both can be used in single and multiplayer Experiences.
{% endhint %}

### **Why use&#x20;**<mark style="color:yellow;">**\[MP]**</mark>**&#x20;objects in a singleplayer game?**

Some logic would cause conflicts between what is visible and what has collisions in a multiplayer Experience, so in some cases there is only a <mark style="color:yellow;">**\[MP]**</mark> version available. <mark style="color:yellow;">**\[MP]**</mark> logic works like <mark style="color:green;">**\[SP]**</mark> logic in a singleplayer Experience.

### **Performance**

<mark style="color:yellow;">**\[MP]**</mark> logic **DOES NOT** reduce gameplay performance in singleplayer games compared to multiplayer games.

### Variables (Game Rules)

Variables can track numbers, time, t/f states, etc. They can be applied to affect data for a **player (P), team (T),** or **global (G)** and change depending on player interactions. Global variables may perform slightly better in singleplayer Experiences.

{% hint style="info" %}
**Global, player,** and **team** variables are unrelated to <mark style="color:green;">**\[SP]**</mark> and <mark style="color:yellow;">**\[MP]**</mark> differences. They can be used in a rule triggered by both types of logic.
{% endhint %}
{% endtab %}

{% tab title="Example: Part 1" %} <img src="/files/1sazsNGJwk1qiXuj6RRp" alt="" data-size="original"> **Objective 1:** Find the key and unlock the break room in 30 seconds

<img src="/files/1Z0dNKrVjSm43D8UsdNS" alt="" data-size="original"> **Game Ruleset:** Countdown [**timer**](/en/creator/game-maker/creative-guides/game-rules-guide/time-trial.md) (triggered with Objective 1)

<img src="/files/6U6IhFRTQhj0b9alLrwX" alt="" data-size="original"><img src="/files/DBNkj5YdhC7jlmzK4Frs" alt="" data-size="original"> <mark style="color:yellow;">**\[MP] Objects:**</mark> Pickable key, Door

**Logic:**

* The player picks up the key and takes it to the door.
* When the door detects the key nearby, it opens.
  {% endtab %}

{% tab title="Example: Part 2" %} <img src="/files/1sazsNGJwk1qiXuj6RRp" alt="" data-size="original">**Objective 2:** Get Seb a drink from the vending machine room

![](/files/1Z0dNKrVjSm43D8UsdNS)**Ruleset:** [**Shop**](/en/creator/game-maker/creative-guides/game-rules-guide/shop.md) (global or local variable for money)

<img src="/files/XCodytYSZHL9QyHghl6q" alt="" data-size="original"><img src="/files/7IWAQ6hT6vbaB6INmqtu" alt="" data-size="original"><mark style="color:green;">**\[SP] Objects:**</mark> Vending machine, Seb NPC, coin

**Logic:**

* Interact with Seb to trigger the quest and turn on quest markers.
* Collect enough coin objects (money variable in the [**Shop**](/en/creator/game-maker/creative-guides/game-rules-guide/shop.md) Ruleset) to buy a drink.
* Interact with the machine to get a drink.
* Return to Seb to give him the drink, which triggers the quest as complete.
  {% endtab %}
  {% endtabs %}

### :busts\_in\_silhouette: Multiplayer

There are two layers of logic that do not communicate with each other, but must be designed to feel seamlessly integrated for players.

{% hint style="success" %}
&#x20;<img src="/files/VkwzAaSKLbL1sMthZ5ok" alt="" data-size="line"> **Multiplayer Simulator**

Toggle the Multiplayer Simulator at the top right in the Editor to test how the Experience will behave if published as singleplayer or multiplayer.
{% endhint %}

{% tabs %}
{% tab title="2 Layers" %}

### Two Layers of Logic

{% hint style="danger" %}
**DESIGN RESTRICTIONS APPLY**

:x: <mark style="color:yellow;">**\[MP]**</mark> and <mark style="color:green;">**\[SP]**</mark> logic **DO NOT** communicate with each other in multiplayer games.

:x: <mark style="color:yellow;">**\[MP]**</mark> logic **DOES NOT** communicate with individual player **Objectives**/quests.

:white\_check\_mark: <mark style="color:yellow;">**\[MP]**</mark> and <mark style="color:green;">**\[SP]**</mark> logic communicate with **Game Rules**.
{% endhint %}
{% endtab %}

{% tab title="Fundamentals" %}
{% hint style="info" %} <mark style="color:green;">**\[SP]**</mark> is ***Client Only*** for individual players and <mark style="color:yellow;">**\[MP]**</mark> is ***Synchronised*** for all players. Both can be used in single and multiplayer Experiences.
{% endhint %}

{% hint style="success" %}
Use **Objectives** for individual player goals. Use [**Crowd Events**](/en/creator/game-maker/docs/behaviours/basic-logic/crowd-event.md) for collective goals.
{% endhint %}

{% hint style="danger" %}
Behaviours and components without <mark style="color:green;">**\[SP]**</mark> or <mark style="color:yellow;">**\[MP]**</mark> in the name are not compatible with multiplayer Experiences yet. They will be ported in the future.
{% endhint %}

### **Why use&#x20;**<mark style="color:green;">**\[SP]**</mark>**&#x20;logic in a multiplayer game?**

<mark style="color:green;">**\[SP]**</mark> logic is necessary in the game world to trigger quests, which track each player's individual progression in your game. Some logic may also only be available as <mark style="color:green;">**\[SP]**</mark>.

### **Performance**

<mark style="color:yellow;">**\[MP]**</mark> logic should be used minimally in multiplayer games to add more gameplay potential without reducing the fun. Start by using as much <mark style="color:green;">**\[SP]**</mark> logic as possible and then add the <mark style="color:yellow;">**\[MP]**</mark> layer. You can build the same player experience that performs more efficiently!

### Consistency <a href="#multiplayer-consistency" id="multiplayer-consistency"></a>

#### **1️⃣ Consistent Type**

An object with <mark style="color:yellow;">**\[MP]**</mark> logic <mark style="background-color:purple;">may only have</mark> other <mark style="color:yellow;">**\[MP]**</mark> logic added.\
An object with <mark style="color:green;">**\[SP]**</mark> logic <mark style="background-color:purple;">may only have</mark> other <mark style="color:green;">**\[SP]**</mark> logic added.

#### **2️⃣ Consistent Messages**

An object with <mark style="color:yellow;">**\[MP]**</mark> logic <mark style="background-color:purple;">may only send messages</mark> to objects with <mark style="color:yellow;">**\[MP]**</mark> logic.\
An object with <mark style="color:green;">**\[SP]**</mark> logic <mark style="background-color:purple;">may only send messages</mark> to objects with <mark style="color:green;">**\[SP]**</mark> logic.

#### **3️⃣ Consistent Hierarchy**

An object with <mark style="color:yellow;">**\[MP]**</mark> logic <mark style="background-color:purple;">may only be a parent or child</mark> of an object with <mark style="color:yellow;">**\[MP]**</mark> logic.\
An object with <mark style="color:green;">**\[SP]**</mark> logic <mark style="background-color:purple;">may only be a parent or child</mark> of an object with <mark style="color:green;">**\[SP]**</mark> logic.

#### **4️⃣ Consistent Spawn**

An object with <mark style="color:yellow;">**\[MP]**</mark> logic <mark style="background-color:purple;">may only spawn</mark> an object or preset with <mark style="color:yellow;">**\[MP]**</mark> logic.\
An object with <mark style="color:green;">**\[SP]**</mark> logic <mark style="background-color:purple;">may only spawn</mark> an object or preset with <mark style="color:green;">**\[SP]**</mark> logic.

### Variables (Game Rules)

Use **global (G), player (P),** and **team (T) variables** depending on how you want number, text, and t/f values to be tracked and affected in your Experience. Learn more about [Game Rules](/en/creator/game-maker/docs/game-rules.md#how-variables-are-applied).

{% hint style="info" %}
Global, player, and team variables are unrelated to <mark style="color:green;">**\[SP]**</mark> and <mark style="color:yellow;">**\[MP]**</mark> differences. They can be used in a rule triggered by both types of logic.
{% endhint %}
{% endtab %}

{% tab title="Example: Part 1" %}
See [**Multiplayer Logic**](#about-multiplayer-logic) below for more details on additional design considerations.

![](/files/1sazsNGJwk1qiXuj6RRp)**Objective 1 (auto trigger at start):** Race to unlock the break room\
\
**Gameplay:**\
All players see the single player objective and rush to find the key

![](/files/1Z0dNKrVjSm43D8UsdNS)**Ruleset:** Countdown [**timer**](/en/creator/game-maker/creative-guides/game-rules-guide/time-trial.md) (triggered with Objective 1)

<img src="/files/6U6IhFRTQhj0b9alLrwX" alt="" data-size="original"><img src="/files/DBNkj5YdhC7jlmzK4Frs" alt="" data-size="original"><mark style="color:yellow;">**\[MP] Objects:**</mark> Pickable key, Door

**Logic:**

* One player picks up the key and takes it to the door.
* When the door detects the key nearby, it open for all players.
  {% endtab %}

{% tab title="Example: Part 2" %}
![](/files/1sazsNGJwk1qiXuj6RRp)**Objective 2:** Get Seb a drink from the machine\
\
**Gameplay:**\
All players explore and find Seb on their own time, triggering logic only they can see.

![](/files/1Z0dNKrVjSm43D8UsdNS)**Ruleset:** [**Shop**](/en/creator/game-maker/creative-guides/game-rules-guide/shop.md) (Local variable - track each player's money)

<img src="/files/XCodytYSZHL9QyHghl6q" alt="" data-size="original"><img src="/files/7IWAQ6hT6vbaB6INmqtu" alt="" data-size="original"><mark style="color:green;">**\[SP] Objects:**</mark> Vending machine, Seb NPC; <mark style="color:yellow;">**\[MP] Object:**</mark> Coin

**Logic:**

* Each player interacts with Seb to trigger dialogue, quest, and quest markers.
* Each player collects enough coin objects (money variable in the [**Shop**](/en/creator/game-maker/creative-guides/game-rules-guide/shop.md) Ruleset) to buy a drink (all coins must be <mark style="color:yellow;">**\[MP]**</mark> and collectable by each player).
* Each player interacts with the machine to get a drink.
* Each player returns to interact with Seb to "give him the drink." A message is sent to **Objectives** to complete the quest.

### Notes on [**Variable Types**](/en/creator/game-maker/docs/game-rules.md#variable-types-1) **in Multiplayer**

**Using a player variable (P)**\
The Shop Preset gives coins to only the players who trigger the rule to earn coins. It tracks this value as it changes (earning or spending) for every player individually.\
\
**Using a global variable (G)**\
The Shop Preset gives coins to all players even if only one player triggers earning them. It tracks this value as it changes (earning or spending).

**Using a team variable (T)**\
The Shop Preset gives coins to a team a player who triggers earning them is assigned to. It tracks this value as it changes (earning or spending) for the whole team.
{% endtab %}
{% endtabs %}

## Resources

* [**Experience Guide**](/en/creator/game-maker/creative-guides/experience-guide.md)
* [**Quality Guidelines**](/en/creator/game-maker/docs/gm-guidelines.md)
* [**Game Production Guide**](/en/creator/game-maker/game-production-guide.md)
* [**Monetisation**](/en/creator/monetisation.md)


---

# 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/build-singleplayer-and-multiplayer-logic.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.
