# Build Multiplayer Games

## Begin Game Maker 8

### Design Multiplayer Game Logic

#### :red\_circle: COMPLEX

In this activity, you will learn the fundamentals of setting up logic layers for multiplayer games, which combines logic individual players experience and synchronized logic all player experience. This includes how variables in the Rules System and Spawn Point behaviors can be used to create teams. Finally, you will learn how to share your Experience for testing or publish it to The Sandbox Map if you own LAND.

{% embed url="<https://youtu.be/JxLaxnTSmGw>" %}

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

### How Does Multiplayer Work?

#### Two Logic Layers

Multiplayer Experiences synchronize data across all players, such as object motion.

However, not all logic needs to be **Synchronized \[MP]** for all players. To improve gameplay performance, some logic can be managed on the individual, or **Client \[SP]**, layer.

When adding logic to an object, you can see a dropdown filter for these communication layers.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FNXJFd6VsujtPjIqgU4CG%2Fimage.png?alt=media&#x26;token=4c50ae8f-00cf-478f-8862-92aed5584550" alt="" width="163"><figcaption><p>Behaviour/component window <br>dropdown filter (top right)</p></figcaption></figure>

### Launch Game Maker

* <mark style="background-color:yellow;">Open the Experience from the previous activity</mark> to reuse some of its logic.
  {% endtab %}

{% tab title="Object Logic" %}

### Object Logic

{% hint style="info" %}
Some behaviours/components only have a **\[MP]** type to prevent conflicts with collisions, movement, etc.
{% endhint %}

#### Consistent Type

* To be compatible in multiplayer games, an object may have only **\[SP]**, only **\[MP]**, or no logic.

{% hint style="success" %}
Remove all logic from an object to change between **\[SP]** and **\[MP]**.
{% endhint %}

**Practice:** Try to add a **\[SP] Toggle** component to the logic asset with **\[MP] Weather Switcher** behaviour added in an earlier activity. You can only add the **\[MP]** version of **Toggle**.

#### Consistent Communications

* In singleplayer Experiences, **\[SP]** and **\[MP]** logic can communicate because all data is managed locally.
* In multiplayer games, **\[SP]** and **\[MP]** logic only "interacts" with its own layer (send/receive messages, detect, collide, spawn, replace, have a parent/child relationship, etc).

**Practice:** Try to send a message to trigger the **\[MP] Weather Switcher** with a **\[SP] Message Broadcaster**. In <img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F47MvTH8onuHiM5XrpD0f%2Fimage.png?alt=media&#x26;token=b0b3845c-914e-4e94-9a62-8504ad2ad9cf" alt="" data-size="line"> singleplayer mode it will work, but in <img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FMSjMvl7GpNgYmhFye00M%2Fimage.png?alt=media&#x26;token=b1427846-22d4-45de-87fc-22981fe7dae1" alt="" data-size="line"> multiplayer mode it will not.
{% endtab %}

{% tab title="Recommendations" %}

### Gameplay Recommendations

{% hint style="warning" %}
In Game Maker 0.10, the Objectives system only communicates with **\[SP]** logic. This limitation will be removed in 0.11, allowing compatibility with **\[MP]** logic.
{% endhint %}

**Practice:** Use the recommendations below to build one or two logic examples in your practice experience based on the gameplay you're interested in exploring.

{% hint style="success" %}
To make a multiplayer Experience feel seamless for players and perform better, use as much **\[SP]** logic in place of **\[MP]** logic as possible.
{% endhint %}

<table><thead><tr><th width="155">Gameplay</th><th>When to use SP</th><th>When to use MP</th></tr></thead><tbody><tr><td>Speaker component</td><td><ul><li>When information is only relevant for an individual player</li></ul></td><td><ul><li>"Barks" to hint all players to talk to an NPC, share general information, etc.</li></ul></td></tr><tr><td>Dialogue (Asker behaviour)</td><td><ul><li>When each player triggers dialogue at their own pace</li><li>Compatibility with quests (0.10)</li></ul></td><td><ul><li>When all players must see dialogue at the same time</li></ul></td></tr><tr><td>Collectables<br><br>(includes<br>consumables &#x26; equipment)</td><td><ul><li>When each player can collect an item (and you need to use less MP logic for improved performance)</li><li>SP compatibility is needed</li></ul></td><td><ul><li>When players compete to collect only one instance of an object (Global set to True)<br>OR<br>When every player can collect an instance of the object (Global set to False)</li><li>MP compatibility is needed</li></ul></td></tr><tr><td>Any use of Game Rules (HUD, banner, key input, variables, etc)</td><td>No limitations<br>(Set Broadcast Type to All to communicate with Game Rules)</td><td>No limitations<br>(Set Broadcast Type to Rules or All to communicate with Game Rules)</td></tr><tr><td>Quests</td><td><ul><li>Only SP logic can communicate with quests in Game Maker 0.10</li></ul></td><td><ul><li>The Quest system will be compatible with MP logic in Game Maker 0.11</li></ul></td></tr><tr><td>Logic that controls movement, collisions, spawning/ destroying, etc.</td><td><ul><li>No SP options exist to avoid physics conflicts</li></ul></td><td><ul><li>Minimize use to boost gameplay performance</li><li>Refer to performance recommendations in Game Maker to choose how many and which logic to use to create an outcome</li><li>Use Actor Property Switcher instead of destroying and respawning objects</li></ul></td></tr></tbody></table>
{% endtab %}

{% tab title="Variables (Rules)" %}

### Variables

The Game Rules system can communicate with **\[SP]** or **\[MP]** logic.

In Game Maker 0.10, global variables apply to all players and local variables apply to individual players. Both work in single player games.&#x20;

**Example:** You can create a global currency for all players to share or local currency for each player to use on their own.

**Practice:** You already have a global variable to count ancient treasures collected from a previous activity. Create a local player variable (integer) named "Player Treasure" with initial value 0. Place collectable **Ancient Treasure B** that sends the message `TreasureB.Collect` to Rules. Add a Math rule to add a fixed value of 100 to the new variable.

{% hint style="info" %}
Game Maker 0.11 will rename the local variable type to "player" and introduce a new "team" variable.
{% endhint %}
{% endtab %}

{% tab title="Teams" %}

### Teams

#### Messaging

Game Maker 0.10 introduced a new way to send messages only to certain teams of players.

Teams are defined by placing multiple [**Spawn Points**](https://docs.sandbox.game/en/creator/game-maker/docs/behaviours/basic-logic/spawn-point-and-avatars-feature) that assign teams randomly when players arrive in the game.

Once teams are defined, you can set the **Broadcast Type** on most logic to Team and select the teams you created from a dropdown list.

**Practice:** Select the Avatars Portal asset and set "Assign Team" to true. Create a team name. Duplicate this object, move it nearby, and create a new team name for it.

#### Customizations

Once teams are created via **Spawn Point** behavior, you can do the following within that logic:

* Choose equipment the team will wear (which can be unique to the team and set them apart)
* Add custom tags for various types of detection
* Add some available components via Avatar's Feature to set the team apart (e.g., light, sound, etc.)

**Practice:** Open each Spawn Point you created and set different equipment per team. At the bottom of the behavior, click "Add Feature" under the Avatar's Feature section. Apply Visual FX and choose a different trailing visual effect for each team.

#### Team Variable

{% hint style="info" %}
A Team variable in Game Maker 0.11 will make it possible to track scores, times, etc. by teams assigned in the Spawn Point.
{% endhint %}
{% endtab %}

{% tab title="Resetting" %}

### Resetting & Instances

{% hint style="info" %}
Instances are different play sessions of an Experience. A new instance opens when a maximum number of players join one. An instance closes after a period of inactivity.
{% endhint %}

Some games must be reset to replay before an instance closes. Logic triggers need to be included in your design to set things back to their original state for players (e.g., variables, respawning removed objects, etc).

This requires careful planning before building your game logic for a single playthrough, and how to do it will vary depending on the gameplay you're designing. Keep this in mind early on as you design logic to create a Experience you want to publish to LAND or share in the Gallery.
{% endtab %}

{% tab title="Test/Share/Publish" %}
{% hint style="warning" %}
Experiences must be marked as multiplayer to allow multiple players to enter.
{% endhint %}

### Test Your Multiplayer Experience

Game Maker is great for rapid testing of singleplayer games, but will not allow multiple players to enter for testing a multiplayer game.&#x20;

You can either generate a test link to open it in the Game Client or share to the public Gallery for testing and feedback.

{% hint style="success" %}
**MULTIPLAYER EXPERIENCE TESTING**

For the most accurate multiplayer results, generate a link to test it in the Game Client software using the <img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FQWb5t8Hf4e3QIo4t7KRC%2Fimage.png?alt=media&#x26;token=1437ac3a-a7cb-48b4-a706-61594ecb114b" alt="" data-size="line"> button in Game Maker (top right).
{% endhint %}

### Share to the Gallery

Shared Experiences are public and can be removed from the gallery when needed. They can be entered into Game Jams and used for playtesting with friends. You can also create a free [experience-page](https://docs.sandbox.game/en/creator/game-maker/publish-experiences/experience-manager/experience-page "mention") to tell players about a shared experience, but keep in mind they can not be linked to from the page or monetized.

**Practice:** Share your practice Experience to the Gallery (don't forget to mark it as multiplayer) and test the logic you created with a friend. Remove it from the Gallery when you're done.

### Publish to the Map

You must own LAND (NFT) to publish your Experience to The Sandbox map and monetize. See our documentation to [publish-experiences](https://docs.sandbox.game/en/creator/game-maker/publish-experiences "mention").&#x20;

Our Experience Manager can help you draw in players from the map, create a free [experience-page](https://docs.sandbox.game/en/creator/game-maker/publish-experiences/experience-manager/experience-page "mention") linked to your Experience, and track player analytics.

**Practice:** Visit The Sandbox [Map](https://app.gitbook.com/s/61fllYo416R30LRxku4v/general/map "mention") to find featured UGC (User Generated Content) Experiences published by our community of creators. Explore their Experience Pages and games to see how you can publish your own.
{% endtab %}
{% endtabs %}

### Follow Up

Multiplayer is a deep and complex topic because it opens up many more game types and specialized approaches to create gameplay. We've introduced some of the key considerations so you can begin to explore it further.

We encourage you to start building your first multiplayer Experience once you feel confident with how to use Game Maker's systems to build logic for a singleplayer Experience.

***

### :heavy\_plus\_sign: Relevant Resources

<table data-view="cards"><thead><tr><th data-type="content-ref"></th><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><a href="../docs/behaviours/basic-logic/spawn-point-and-avatars-feature">spawn-point-and-avatars-feature</a></td><td>Set up teams, starter equipment, and components (features) to apply to players by spawn point.</td><td><a href="../docs/behaviours/basic-logic/spawn-point-and-avatars-feature">spawn-point-and-avatars-feature</a></td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FMkKddKfm0hj9Y1Rgj6je%2FGM%20Spawn%20Point%20behavior%20sm%20opt.gif?alt=media&#x26;token=7dfd61ec-52bd-4211-a7ab-f275cfdce9c4">GM Spawn Point behavior sm opt.gif</a></td></tr><tr><td><a href="../docs/behaviours/modifiers/actor-property-switcher">actor-property-switcher</a></td><td>Change the properties of objects, such as visibility, collisions, gravity, and UI visibility for dynamic yet optimised gameplay logic.</td><td><a href="../docs/behaviours/modifiers/actor-property-switcher">actor-property-switcher</a></td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FWljBafgDSvNKbbHRB5GK%2FGM%200.10%20actor%20property%20beh%20visiblity%20of%20indicator%20UI.gif?alt=media&#x26;token=9d47c38c-6906-4842-b425-59e54fd7eea7">GM 0.10 actor property beh visiblity of indicator UI.gif</a></td></tr><tr><td><a href="../docs/build-singleplayer-and-multiplayer-logic">build-singleplayer-and-multiplayer-logic</a></td><td>See how logic works differently in singleplayer and multiplayer games and how to optimise with our guidelines.</td><td><a href="../docs/build-singleplayer-and-multiplayer-logic">build-singleplayer-and-multiplayer-logic</a></td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FBQV32hW3mpgMGvWKaRga%2FBuild%20SP%20%26%20MP%20Gameplay.png?alt=media&#x26;token=c5b8135d-ef12-4487-84b8-55daeb84d384">Build SP &#x26; MP Gameplay.png</a></td></tr><tr><td></td><td><a href="https://www.sandbox.game/en/events/?filter=creators">Creator Events: Game Jams</a><br>Join a Game Jam to challenge yourself to grow as you practice applying your skills and explore creating new things. You <strong>do not</strong> need to own LAND to participate!</td><td><a href="https://www.sandbox.game/en/events/?filter=creators">https://www.sandbox.game/en/events/?filter=creators</a></td><td><a href="https://content.gitbook.com/content/83PS3g9zpWmq73xzlwFn/blobs/Q4ZvJ1bX4Kpmx2mCt79y/GameJam_Logo-1.png">GameJam_Logo-1.png</a></td></tr><tr><td><a href="../publish-experiences/experience-manager/experience-page">experience-page</a></td><td>Create a free Experience Page, even if you don't own LAND! Hook players on a story, wow Game Jam judges, provide extra details for play, or announce rules for your own contests.</td><td><a href="../publish-experiences/experience-manager/experience-page">experience-page</a></td><td><a href="https://content.gitbook.com/content/83PS3g9zpWmq73xzlwFn/blobs/Vrok7XS9y5nYmpPIJlcV/EX%20page%20banner.png">EX page banner.png</a></td></tr><tr><td><a href="../publish-experiences">publish-experiences</a></td><td>Launch an Experience on the map if you own LAND. Learn about the Experience Manager's tools, content upload specifications, marketing, making trailers, and player engagement.</td><td><a href="../publish-experiences">publish-experiences</a></td><td><a href="https://content.gitbook.com/content/83PS3g9zpWmq73xzlwFn/blobs/HwQlR47DMiEFYht5enEJ/Full%20map%20Voxel.png">Full map Voxel.png</a></td></tr><tr><td><a href="../game-production-guide">game-production-guide</a></td><td>See the workflow teams use to publish professional content and try it out for yourself. We break it down into easy actionable steps!</td><td><a href="../game-production-guide">game-production-guide</a></td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FILL8WmeB1jnKjsXtk7ae%2Fproduction%20guide.png?alt=media&#x26;token=2a3ade5b-e76e-4c14-990a-f37c64f938de">production guide.png</a></td></tr><tr><td><a href="../docs/gm-guidelines">gm-guidelines</a></td><td>Use our guidelines to plan ahead, add polish, and test carefully to ensure your game is fun and functional.</td><td><a href="../docs/gm-guidelines">gm-guidelines</a></td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FLmsi3jjwW7UJisIT1a0V%2FWhitelist.png?alt=media&#x26;token=47a66de2-4faa-44ea-b8ff-36e2193e06af">Whitelist.png</a></td></tr><tr><td><a href="../docs/gm-guidelines/playability">playability</a></td><td>Make games easier to play! Improve your Experience page, use assets as visual aids, build in hands-on tutorials, and more.</td><td><a href="../docs/gm-guidelines/playability">playability</a></td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fh6NeJaBRaQGsdZ7kAtfO%2Fimage.png?alt=media&#x26;token=6440e192-07c1-45dc-8893-f930f041b790">gm playability trendy factory quick learn.png</a></td></tr></tbody></table>

***

## Forum: Community Ideas & Support

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="https://forum.sandbox.game/t/begin-game-maker-series-8-build-multiplayer-games/1849"><strong>Visit the Forum</strong></a></td><td><a href="https://content.gitbook.com/content/83PS3g9zpWmq73xzlwFn/blobs/R2GdZMImITUqYrmiThBY/13%20community%20%20-%20%20blog.png">13 community  -  blog.png</a></td><td><a href="https://forum.sandbox.game/t/begin-game-maker-series-8-build-multiplayer-games/1849">https://forum.sandbox.game/t/begin-game-maker-series-8-build-multiplayer-games/1849</a></td></tr><tr><td><p>A forum post has been created for this learning activity! Visit to:</p><ul><li>Ask or answer questions</li><li>Post ideas about the topic</li><li><p>Share what you've learned or created</p><ul><li>from the activity</li><li>from the bonus resources</li></ul></li></ul></td><td></td><td><a href="https://forum.sandbox.game/t/begin-game-maker-series-8-build-multiplayer-games/1849">https://forum.sandbox.game/t/begin-game-maker-series-8-build-multiplayer-games/1849</a></td></tr></tbody></table>

***

## Other "Begin Game Maker" Videos

<table data-header-hidden><thead><tr><th data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="play-test">play-test</a></td></tr><tr><td><a href="build-with-blocks">build-with-blocks</a></td></tr><tr><td><a href="place-assets">place-assets</a></td></tr><tr><td><a href="set-object-actions">set-object-actions</a></td></tr><tr><td><a href="trigger-logic">trigger-logic</a></td></tr><tr><td><a href="craft-quests">craft-quests</a></td></tr><tr><td><a href="set-up-mechanics">set-up-mechanics</a></td></tr><tr><td><a href="build-multiplayer-games">build-multiplayer-games</a></td></tr></tbody></table>
