Bash.tv → GitHub → itch.io

Record and replay gameplay by saving inputs instead of video. Determinism rules (fixed time step, seeded random numbers, no wall clock), a tested recorder that stores only input changes, playback with pause, speed and fast seeking through keyframes, state hashes to detect desync, server-side replay verification to catch forged scores, compact share codes (gzip and base64url) for links, ghost ra...

Download skill (.zip) Files on GitHub

Game replay system

Save inputs per frame, not pictures. Re-running the same inputs through the same deterministic game gives the same result: a 3-minute run is a few KB, can be shared in a link, and can be checked by a server.

Make the game deterministic

  1. Fixed steps: update(1/60) from an accumulator (the scaffold loop does this). Never step with the real frame time.
  2. Seeded randomness: const rng = seeded(seed) and use rng() everywhere in game logic. Math.random() is fine for visual-only effects (particles), never for anything that changes the outcome.
  3. No clocks or devices in logic: no Date.now(), performance.now(), screen size or frame rate in rules.
  4. Order: iterate arrays, not objects with changing keys; don’t depend on Set order after deletes.
  5. Same code version: store meta.version and refuse replays from other versions (or keep old rules).
  6. Math functions (Math.sin etc.) can differ in the last digit between browsers. Fine for replays on the same browser; for cross-browser verification round state (hashState rounds to 1e-6) or use integer and fixed-point positions.

assets/replay.js

import { seeded, createRecorder, createPlayback, verifyReplay, hashState, encodeReplay, decodeReplay } from "./replay.js";
const rec = createRecorder({ seed, meta: { game: "my-game", version: "1.2.0" } });
each fixed step: rec.record(input); state = step(state, input, rng);
const replay = rec.finish({ score: state.score, hash: hashState(state) });
const code = await encodeReplay(replay);          // share: https://my.game/?replay=CODE

const pb = createPlayback(replay, { init: (seed) => ({ state: newGame(), rng: seeded(seed) }), step, keyEvery: 300 });
each frame: pb.update(realDt); draw(pb.state);  pb.paused = true; pb.speed = 4; pb.seek(frame); pb.progress

Inputs are actions ({ left: true, jump: false }), recorded only when they change, so holding a key costs nothing.

Uses

Tested

Node tests: 1,000 frames stored as about 16 input changes, verification passing, a forged score caught, playback ending in the same state hash, seeking backwards and forwards giving identical states, 2x speed, encode/decode round trip with URL-safe characters.

Pitfalls

Variable time steps, unseeded randomness, recording positions instead of inputs, replays from older game versions, and reading Date.now() in game logic.