taking longer than usual.

skip to content
sometimes/ developers

developers / games / start here

your first change

this tutorial changes the counter to add two on each click and verifies that both players receive the updated value.

API 1 · SDK 1.0.2download reference

1. open the project

finish the quickstart, then open the my-game folder in your editor. client.ts creates the screen; server.ts owns the shared count. game.json describes the game. package.json lists dependencies and commands. you do not need to edit node_modules or output.

2. change the rule

replace server.ts with this code. init creates a new match at zero. action accepts only the increment command and adds two. view returns the count to each player. only the server changes the shared score, so editing a label cannot change the rules.

import { defineGame, GameError } from "@sometimes/games/server";

export default defineGame({
  init: () => ({ count: 0 }),
  action(state, name) {
    if (name !== "increment") {
      throw new GameError("invalid", "unknown action.");
    }
    state.count += 2;
  },
  view: state => ({ count: state.count }),
});

3. change the button

in client.ts, find the line below and change add one to add two. keep the existing click handler: it sends the increment action, handles errors and renders the server's response. the subscription updates the other player's screen.

button.textContent = "add two";

4. check the result

save both files. stop the simulator with Ctrl+C, run npm run dev again, and reload its printed URL. both counters start at 0. click add two in the first screen: both should show 2. click it in the second: both should show 4. try mobile view and disconnect/reconnect. restarting this local simulator starts a fresh match; production rooms persist their state.

shell
npm run dev

5. package the game

run npm run build to create output/game.sometimes.json, which you can upload in the developer dashboard. further changes follow the same process: add state fields and validated actions on the server, return permitted fields in view, and render the result in the client. the Wordle example demonstrates this structure in a complete game.