> ## Documentation Index
> Fetch the complete documentation index at: https://docs.summerengine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Make a multiplayer game on Summer Games

> Build an online multiplayer game with Summer Engine: one project, a server that owns the rules, the client code that joins a match, Local Play with several players, and hosted matches.

A Summer multiplayer game is **one project with two starting scenes**. The
**client** scene is what every player runs: input, camera, visuals and menus.
The **server** scene runs without a screen and owns the rules: the score, the
doors, who won. Summer runs the server for every match, so no player has to
host, and nobody needs to share an address.

The same code runs on your machine and once the game is published. There's no
separate "server version" to keep in sync, and no local-only shortcuts to
remove later.

## How it fits together

![Each player's device runs the client scene and moves its own character. One Summer server runs the server scene for the match, checks what players do and sends everyone the results.](https://mintcdn.com/summer-18f03259/_ENGS2HrEIacSS6a/images/guide-art/multiplayer/overview-light.svg?fit=max\&auto=format\&n=_ENGS2HrEIacSS6a\&q=85\&s=c87c64471acd5c135466afd4be0cd251)

A few words come up on every page in this section:

* **World:** one running match or shared place, run by one server. A
  10-minute round is a World, and so is a server that stays up for weeks.
* **Session:** one player's seat in a World. Summer checks who the player is
  before they get one, so your server always knows exactly who did what.
* **Queue:** how players find a World, such as "casual" or "ranked 2v2". See
  [Match players into games](https://docs.summerengine.com/build/matchmaking.md).

![Players in a queue are placed into a World. Inside the World, each player has a Session: their verified seat.](https://mintcdn.com/summer-18f03259/_ENGS2HrEIacSS6a/images/guide-art/multiplayer/words-light.svg?fit=max\&auto=format\&n=_ENGS2HrEIacSS6a\&q=85\&s=f0878247dbffc257490d6d0aeb7bd9b3)

## What your players get

* **Instant controls.** Each player's own character responds the moment they
  press a key, on any connection. See [Make movement feel instant](https://docs.summerengine.com/build/movement.md).
* **A fair game.** The server checks every move and request, so a modified
  client can't give itself points, speed or items.
* **Nobody ends the match by leaving.** No player is the host. If someone
  quits or drops out, everyone else keeps playing, and a player who reconnects
  in time gets their seat back.
* **The same account everywhere.** Players sign in once with their Summer
  account, and your game sees their name in every match.

## Start here

**Make my game multiplayer.** Your agent sets up both scenes, joining, and a first Local Play run.

Make my Summer project multiplayer. Use the Summer `multiplayer` skill to plan
it and the `multiplayer-project` skill to set it up; if you don't have them
installed, find them in the Summer library.

* Split the game into a client scene every player runs and a server scene that
  owns the rules.
* Players join a match from my existing menu.
* Every player sees one character per player who joined.

Read my project first and tell me what moves to the server and what stays on
the client before you change anything. Then run it with Local Play with two
players and tell me what you saw.

Your agent works through Summer's multiplayer skills in this order. Each one
continues the same example game, so you can also ask for them one at a time:

| Skill | What it adds |
| - | - |
| [`multiplayer`](https://docs.summerengine.com/skills/multiplayer) | The plan: what the server owns and what each player runs |
| [`multiplayer-project`](https://docs.summerengine.com/skills/multiplayer-project) | Both scenes, the World and queue files, joining, a first Local Play |
| [`multiplayer-movement`](https://docs.summerengine.com/skills/multiplayer-movement) | Movement that responds at once for the player and looks smooth for everyone else |
| [`multiplayer-state`](https://docs.summerengine.com/skills/multiplayer-state) | Scores, doors, pickups, health and private state |
| [`multiplayer-testing`](https://docs.summerengine.com/skills/multiplayer-testing) | Local Play with many players and a bad connection |
| [`multiplayer-publish`](https://docs.summerengine.com/skills/multiplayer-publish) | The export with its server, ready for Summer Games |

## The project

One project holds both sides. Each folder belongs to one side:

```text theme={null}
project.godot            shared
summer.build.json        the Build: game id, queues, Worlds, server export preset
world.json               the World: which scene runs on the server, which on players' devices
network/                 shared by both sides: the network composition and shared code
client/                  what players run: main scene, player scenes, UI
authority/               what the server runs: main scene and the rules
```

Client code never loads a file from `authority/`, and the export for players
leaves that folder out.

## The code

This is the client's main script from the `multiplayer-project` skill. It
starts Summer, joins the match queue, and tells the server it has arrived. Each
player runs it. The other files, scenes included, are in
[the complete files](https://docs.summerengine.com/skills/multiplayer-project/files.md), and every one of them
ran as shown under Local Play.

```gdscript client/main.gd theme={null}
extends Node
## What each player runs: joins the match and shows every player.

const Game = preload("res://network/game.gd")
const PlayerArchetype = preload("res://client/player_archetype.tres")

var spawner: SummerNetworkSpawner

func _ready() -> void:
	spawner = Game.build_network(self, PlayerArchetype)
	# Connect signals like state_group_created here, before joining, or values
	# that arrive during the join go unseen (multiplayer-movement adds them).
	var initialized: SummerResult = await Summer.initialize().get_result_or_completed_signal()
	if not initialized.ok:
		push_error(initialized.message)
		return
	var join := Summer.client.join(SummerJoinTarget.queue(Game.QUEUE))
	# Hosted matchmaking may ask the player to accept a match.
	join.acceptance_required.connect(func(proposal: SummerMatchmakingProposal) -> void: proposal.accept())
	var joined: SummerResult = await join.get_result_or_completed_signal()
	if not joined.ok:
		push_error("join failed: %s %s" % [joined.code, joined.message])
		return
	if not spawner.is_network_ready():
		await spawner.network_ready
	var entered := await command({"c": "join"})
	if not entered.ok:
		push_error("could not enter the match: %s" % entered.error)
		return
	print("COURTYARD_CLIENT_JOINED")

## Sends one Command and waits for the authority's answer.
func command(payload: Dictionary) -> Dictionary:
	var admission := spawner.enqueue_command(Game.CMD, Game.pack(payload))
	if not admission.is_enqueued():
		return {"ok": false, "error": String(admission.get_code())}
	var handle := admission.get_handle()
	if not handle.is_terminal():
		await handle.completed
	if handle.get_outcome() == SummerNetworkCommandHandle.OUTCOME_ACCEPTED:
		return {"ok": true, "error": "", "result": Game.unpack(handle.get_result())}
	return {"ok": false, "error": String(handle.get_reason())}
```

Three rules hold for every Summer multiplayer game:

* **`Summer.initialize()` takes no game ID.** Summer knows the game from where
  it runs: Local Play, the hosted server or the Summer Games app.
* **The server decides.** Players send requests, called Commands, and the
  server accepts or refuses each one. It reads who sent a Command from the
  verified session, never from the payload.
* **Use Summer's multiplayer nodes**, `SummerNetworkWorld` and
  `SummerNetworkSpawner`, not hand-written networking. That is what lets Summer
  host the match, check every player and keep the game fair.

Every method and signal: [`Summer.client`](https://docs.summerengine.com/api-reference/gdscript/client),
[`Summer.multiplayer`](https://docs.summerengine.com/api-reference/gdscript/multiplayer) and the
[Summer API overview](https://docs.summerengine.com/api-reference/gdscript/overview.md).

## Testing it on your machine

**Local Play** runs your whole multiplayer game on one computer. Summer starts
the server scene in the background plus one game window per player, side by
side, each signed in as a test player. No account, server or extra tools are
needed.

![Pressing Play in Summer starts the server scene in the background and three game windows side by side, each signed in as a different test player.](https://mintcdn.com/summer-18f03259/_ENGS2HrEIacSS6a/images/guide-art/multiplayer/local-play-light.svg?fit=max\&auto=format\&n=_ENGS2HrEIacSS6a\&q=85\&s=cf61858aa075d9b7322638bd6b2aa084)

Start it any of these ways:

* **Your agent**: ask for "a Local Play test with two players".
* **The editor**: choose the number of players in **Debug > Local Multiplayer**, then press Play.
* **A terminal**, while Summer Engine is open:

  ```bash theme={null}
  npx -y summer-engine@latest engine play --players 2
  ```

The number of players defaults to the queue's `minPlayers` in
`summer.build.json`, or 2.

Your own machine has no lag, which hides timing problems. Local Play can add
delay, jitter and packet loss to every window: set
`summer/local_play/network/round_trip_msec`, `jitter_msec` and `loss_percent`
in Project Settings, or ask your agent. Run it that way before you call a
feature done.

**Test my multiplayer game on a bad connection.** Several players, real lag, and what a passing run shows.

Test my Summer multiplayer game with Local Play. Use the Summer
`multiplayer-testing` skill; if you don't have it installed, find it in the
Summer library.

* Run \[N] players, first on a normal connection and then with added delay,
  jitter and packet loss.
* Walk through \[THE FEATURE] in every window.
* Tell me exactly what you saw in each window, and anything that looked wrong.

**Limits today:** up to 16 players in one match.

## Where to go next

> [card] [Match players into games](https://docs.summerengine.com/build/matchmaking.md)
>
> Quick play, ranked, teams and the accept prompt.

> [card] [Let friends play together](https://docs.summerengine.com/build/parties.md)
>
> Friends queue as a party and land in the same match.

> [card] [Keep a world running](https://docs.summerengine.com/build/persistent-worlds.md)
>
> Worlds that save and come back between sessions.

> [card] [Make movement feel instant](https://docs.summerengine.com/build/movement.md)
>
> Your character responds at once; others glide smoothly.

> [card] [Make hits fair](https://docs.summerengine.com/build/hit-detection.md)
>
> Shots are checked against what the shooter saw.

> [card] [Share the game world](https://docs.summerengine.com/build/shared-state.md)
>
> Scores, doors, pickups and private hands of cards.

> [card] [Save player progress](https://docs.summerengine.com/build/player-progress.md)
>
> Progress that follows the player into every match.

> [card] [Ratings and leaderboards](https://docs.summerengine.com/build/leaderboards.md)
>
> Skill ratings, score boards and the top 50.

> [card] [End a match and show results](https://docs.summerengine.com/build/match-results.md)
>
> Wins, losses and rating changes.

> [card] [Friends and messages](https://docs.summerengine.com/build/friends.md)
>
> See who's online and message them.

> [card] [Text chat](https://docs.summerengine.com/build/chat.md)
>
> Chat inside a World.

> [card] [Sell items for Sparks](https://docs.summerengine.com/build/store.md)
>
> A store in your game, checked out by Summer.

> [card] [Cosmetics](https://docs.summerengine.com/build/cosmetics.md)
>
> Skins and outfits players own and wear.

> [card] [Paid games and tips](https://docs.summerengine.com/build/paid-games.md)
>
> Charge for your game or let players support you.

> [card] [Server size and player count](https://docs.summerengine.com/build/server-size.md)
>
> Pick how big each World's server is.

> [card] [Console commands](https://docs.summerengine.com/build/console-commands.md)
>
> Type commands into a live World.

> [card] [Analytics](https://docs.summerengine.com/build/analytics.md)
>
> See what players do in your game.

> [card] [Publish your game](https://docs.summerengine.com/build/publish.md)
>
> Ship it to players on summer.games.

### Games like yours

> [card] [Tactical shooters](https://docs.summerengine.com/build/games-like/tactical-shooter.md)
>
> Round-based team shooters.

> [card] [MOBAs](https://docs.summerengine.com/build/games-like/moba.md)
>
> Ranked team battles with an accept prompt.

> [card] [Survival and sandbox](https://docs.summerengine.com/build/games-like/survival-sandbox.md)
>
> Worlds players build in and come back to.

> [card] [Co-op games](https://docs.summerengine.com/build/games-like/co-op.md)
>
> A small group against the game.

> [card] [Party games](https://docs.summerengine.com/build/games-like/party-games.md)
>
> Quick, casual rounds with friends.

> [card] [Card and turn-based games](https://docs.summerengine.com/build/games-like/card-games.md)
>
> Private hands, shared boards, rated duels.

> [card] [Single-player and mobile games](https://docs.summerengine.com/build/games-like/single-player.md)
>
> Accounts, saves and a store.

***

Does this not help you? [Reach out on Discord!](https://discord.gg/summerengine)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.