---
title: Rooms
description: "Add the bundled Rooms package to a Tide game for one standard
  menu: play alone, host and join rooms with codes and invite links, how to
  play, volume settings and customizable pages."
source_url: https://tide-engine.dev/packages/rooms
source_file: docs/packages/rooms.md
source_revision: d46b7bc81b49e31e268bd62d158c040ec1c9ff21
source_worktree: modified
documentation_sha256: cff5cc1f43e9cab7c438614cde0e25d6b097b0171d16e0bfbecd7198624f4f9d
documentation_scope: Website source checkout; not matched to an installed Tide
  release. Check tide version and the project toolchain.
---

<a id="rooms"></a>

# Rooms

`rooms` is an optional package bundled with Tide, in the namespace `Rooms`. It provides a ready-made menu over the engine's [sessions and room codes](https://tide-engine.dev/multiplayer/matches.md). The engine can host and join matches without this package; Rooms supplies the pages and buttons players use to do it.

<a id="using-rooms"></a>

## Using Rooms

A game needs all of the above before two people can play it, and a menu to reach them from. The `rooms` package is that menu, so a game has one from its first day and writes its own when it's ready. List it in the game's `tide.packages`:

```
rooms
```

The game then opens on a title page: its name, a line that says what it is, who it's for, and **Play alone**, **Host a room** and **Join a room**, with how it's played beside them. There's a page to type a friend's code into, which Enter joins from; and the room's page, with its code in large letters and an invite to copy (on the web, **Copy the invite link**: a link to the game's page that joins the room when a friend opens it; elsewhere, **Copy the code**, for a friend to type in), a line that says what to do with it, who's in the room, **Play** or **Resume**, **How to play** and **Leave the room**. In the match, **Menu** in the top right corner, Escape or a gamepad's Start brings the room's page back. It's drawn over a live match: `Main` stays the match's, so the game runs behind the title, and **Play alone** closes the menu. A game started with `--host` or `--join`, or a page opened with `?host` or `?join=`, has no menu in its way. A match that ends, or a room that can't be joined, puts the machine back on the title with a line that says why.

Every game that lists the package has the same menu: the same pages, words and look. A player who has hosted a room in one knows how in the next, and a game says only what's its own.

<a id="what-a-game-says"></a>

## What a game says

The title is the game's `title` setting (`Application.title`). The rest is functions the game [overrides](https://tide-engine.dev/language/overrides.md), each with a default:

```csharp
using Rooms;

override string Rooms.Tagline() { return "Race to stack falling bricks into the tallest tower."; }
override string Rooms.Players() { return "1 to 4 players"; }

override string Rooms.HowToPlay()
{
    return "Build higher than everyone else before the clock runs out.\n"
         + "A and D, or the arrows: move the brick\n"
         + "Q and E: turn it\n"
         + "Space: drop it";
}
```

| Function | What it says | Without an override |
|---|---|---|
| `Rooms.Title()` | The game's name | The `title` setting |
| `Rooms.Tagline()` | What the game is, in a sentence | A line about playing alone or with friends |
| `Rooms.Players()` | Who it's for: "1 to 4 players" | Nothing |
| `Rooms.PlaysAlone()` | Whether one player has a game. `false` leaves **Play alone** out, and the title says to host a room or join one | `true` |
| `Rooms.HowToPlay()` | How it's played, a line each with `\n` between them: what the game asks first, then its controls | Nothing, and no **How to play** |
| `Rooms.Look()` | The pages' [theme](https://tide-engine.dev/game/gui.md#themes) | The package's look |
| `Rooms.MenuButton(screen)` | Where **Menu** goes during a match | The top right corner of [`Screen.safeArea`](https://tide-engine.dev/game/gui.md#the-safe-area), clear of a phone's notch: the bottom of the screen is the game's, for its hints and a phone's thumbs |

How to play is beside the title's buttons where the screen has room for both, and behind a **How to play** button where it hasn't, as on a phone. The room's page has the button too, so it's a press away during a match. Long lines wrap.

On a screen as short as a phone on its side, the pages take their shortest form: the name and the buttons on the title, and the room's code, its copy button and its buttons side by side on the room's page.

On the web, copying the invite stays disabled until the relay confirms the room is registered. The code can already be visible while the room is opening.

**Settings** on the title or room's page opens a **Volume** slider, from mute to full volume, for this machine's audio. Changes apply at once; **Back** or Escape returns to the page that opened it. The local `Lobby.volume` goes from `0` to `1` and starts at `1`. It stays through starting, joining and leaving matches while the game is open, and resets to full volume when the game restarts. The settings page has `Lobby.page == Page.Settings`, so the same HUD and input checks below cover it.

The pages are the GUI's own widgets, in the package's look whatever theme the game sets for its own (`Rooms.Look()` changes it), and the devices are theirs while a page is up. What the game reads of it is one local singleton, `Lobby`, through `using Rooms;`:

```csharp
using Rooms;

input Controls
{
    bool jump;

    Sample(Devices devices, Lobby lobby)
    {
        // Nothing is sent while a page is up, or until the press that closed it is let go
        jump = lobby.playing && devices.keyboard.space.down;
    }
}

view Hud(Lobby lobby)
{
    if (lobby.page != Page.Playing) return;
    ...
}
```

A game can tell the room's page about its match, each frame, from a view that writes `Lobby`: `seats`, `manned` (a bit per seat a player has), `mine` and `bots` say who has each seat (a line a seat up to four, and one line for all of them past that), and `offersNewGame` and `offersBots` put **New game** and **Bots: on/off** on the page, which set `newGame` and `toggleBots` for the frame they're pressed in, for the game to call its commands from. **Play alone** on the title sets `newGame` too.

<a id="pages-of-your-own"></a>

## Pages of your own

Each page is a function too, which a game overrides to draw that page its own way while the others stay the package's: `Rooms.TitlePage(session, lobby)`, `Rooms.JoinPage(session, lobby)`, `Rooms.RoomPage(session, room, invite, lobby)` (`room` is the room's code, `session.room`, and `invite` what others open to join it, `session.invite`, which a function is handed), `Rooms.HelpPage(lobby)` and `Rooms.SettingsPage(lobby)`. A page of the game's is no longer the menu players know from other games, so it's for a game that has outgrown the standard one. What a page's buttons do is a call each, so a page of the game's keeps the menu's way through its pages:

```csharp
using Rooms;

override void Rooms.TitlePage(Session session, mut Lobby lobby)
{
    if (GUI.Button(Rect(40, 200, 200, 48), "Play")) Play(lobby);
    if (GUI.Button(Rect(40, 256, 200, 48), "Play with friends")) Host(lobby);
    if (GUI.Button(Rect(40, 312, 200, 48), "Enter a code")) ShowJoin(lobby);
    if (GUI.Button(Rect(40, 368, 200, 48), "Settings")) ShowSettings(lobby);
}
```

| Call | What it does |
|---|---|
| `Play(lobby)` | Into the match, as a new game: the game sees `newGame` |
| `Resume(lobby)` | Into the match as it is |
| `ShowRoom(lobby)` | The room's page over the match, as **Menu** brings it |
| `Host(lobby)` | Opens the match to others, and shows its room |
| `Invite()` | Opens the match to others from the room's page |
| `ShowJoin(lobby)` | To the page a code is typed into |
| `Join(lobby, code)` | Asks to join the room with that code |
| `LeaveJoin(session, lobby)` | From the Join page to the title, out of a match that was being joined |
| `ShowSettings(lobby)`, `LeaveSettings(lobby)` | To the settings, and back to the page they came from |
| `ShowHelp(lobby)`, `LeaveHelp(lobby)` | To how the game is played, and back to the page it came from |
| `CopyInvite(lobby, invite)` | Copies the room's invite: on the web a link that joins it, elsewhere its code |
| `CopyCode(lobby, room)` | Copies the room's code |
| `Leave(session, lobby)` | Out of the room, to the title |

An override has the parameters of what it replaces, so a page that needs more (the game's own state, or `Devices`) is a view of the game's: override the package's page with an empty body, and draw yours from a view that returns unless `lobby.page` is that page. The same calls work there.

<a id="outgrowing-it"></a>

## Outgrowing it

`tide eject rooms` copies the package into the game, as `packages/rooms`, and points the game's `tide.packages` line at the copy: it's the game's own from there, to change as you like, and `tide upgrade` no longer updates it. It's a page of Tide, written with nothing a game can't use.

A game whose players gather before a match, see who's ready, browse what's open or press one button to find a match lists the `lobby` package instead: see [Lobbies and matchmaking](https://tide-engine.dev/packages/lobby.md).
