Play with friends
Goal
The third-person game in rooms: two tabs (or two people) in one arena, each with their own character, the authority on a room server. The page shows the room code with a copy-link button, and a game opened with no room still plays solo.
Files you will edit
src/game.ts
Steps
Declare the feature. In
src/game.ts, addmultiplayerbesidecharacters:tsfeatures: { characters: true, multiplayer: { maxPlayers: 6 } },That is the only edit. The page (
src/main.ts) sees it and becomes a room's client: no physics on the page, the authority's world drawn instead, and?room=picks the room.Start the room server beside the dev server, in two terminals:
shnpm run dev # the page, http://localhost:5181 npx gameable serve --direct # the room server, ws://localhost:8790--directrunssrc/game.tsas-is, one room at a time; it accepts pages fromhttp://localhost:*andhttp://127.0.0.1:*. It readssrc/game.tsonce, so restart it after an edit. Inside the engine repository, runnpm run buildonce first:npx gameableruns the CLI's builtdist/.Open a room in the first tab:
http://localhost:5181/?room=new&rooms=http://localhost:8790. Once it joins, the corner shows a four-letter code and the address becomes?room=CODE, so a reload keeps your seat. Copy link and open it in a second tab.
The address picks the room: no ?room= plays solo, ?room=CODE joins, ?room=new makes a room and ?room=quick joins any open one. ?rooms= works only on a local page; a deployed game uses its own server.
Verify
sh
npm testIn both tabs the corner says Joined with the same code; walk in one and the other character moves in the other tab. A failed join says why: full, no-room, origin or capacity. With no ?room=, run npm run build:guest first: Play Solo's authority is the built guest.
See also
- Turn on a feature — how
featuresreach the page - Build the wasm guest — what Play Solo's authority runs
- Build your first adventure — the template this extends