Skip to content

Make a multiplayer game ​

From nothing to two tabs on one course, with the race kit: a multiplayer game that already works, for you to change.

1. Pick a kit ​

sh
npm create gameable -- --list

prints every template, one line each, with race marked as multiplayer:

KitPlayersWhat it is
race1-12obstacle race with jumps, sweepers, checkpoints and places

Race is also hosted on the Play page. Play together opens a room on the hosted room server; copy the link the corner shows into a second tab and you are two players, with nothing installed.

2. Scaffold ​

sh
npm create gameable my-race -- --template race
cd my-race
npm install
npm run build:guest   # Play Solo's authority runs the wasm guest
npm run dev           # http://localhost:5199

The page plays solo: a room of one, the authority in the page. WASD walks, Space jumps and the mouse orbits. Solo starts after a three-second wait and a three-second countdown. Falling returns you to your last checkpoint. Paste a published link in Your character or use ?look= to choose your look.

3. Start a room server ​

In a second terminal, in the same directory:

sh
npx gameable serve --direct   # the room server, ws://localhost:8790

--direct runs src/game.ts as it is, with no build. It reads the file once, so restart it after an edit. It takes pages from http://localhost:* and http://127.0.0.1:*.

4. Two tabs ​

Open http://localhost:5199/?room=new&rooms=http://localhost:8790. Once it joins, the corner shows a four-letter code and Copy link. Open the link in a second tab: two racers on one course, each moving in their own tab and seen in the other. The second player starts a five-second wait, followed by a three-second countdown. Race to the finish line to see your places.

The address picks the room: ?room=new makes one, ?room=CODE joins it, ?room=quick joins any open one, and no ?room= plays solo. ?rooms= works only on a local page; a deployed game talks to its own site's room server.

5. Change something ​

The layout and tuning are in src/course.ts. Change walkSpeed and runSpeed in RULES from 4 to 5, restart serve --direct, and reload both tabs. Both racers now move faster; prediction uses the same movement system on the page and the authority. Rebuild the guest before trying Play Solo after an edit.

Run the kit's tests, which drive the authority headlessly without a browser:

sh
npm test

See also ​

  • Multiplayer: rooms, the authority, players
  • Play with friends: the third-person template in rooms, with one edit
  • Play: the hosted games
  • Ship it: the page is static files; the room server runs gameable serve on built games