Weezdraw Game SDK 2

The SDK connects your HTML5 game to Weezdraw: it reports each game's result, gives every player of a competition the same random numbers, and lets the platform pause or mute your game. It is a single script with no dependencies (about 5 KB gzipped). It works with any web game engine (plain JS, Phaser, PixiJS, Three.js, Construct…); a Unity WebGL build can call window.WZ from a .jslib plugin.

1. Quick start

Add the SDK to the <head> of your index.html:

<script src="https://weezdraw-sdk.vercel.app/sdk/v2/weezdraw-sdk.js"></script>

Then, in your game code:

await WZ.init();                 // once, at startup

// when the player presses Play:
const start = await WZ.gameplayStart();
if (!start.allowed) showNoMoreGamesScreen();

// when the game is over (all lives lost, level won, time out…):
await WZ.points(finalScore);      // or WZ.time(ms) / WZ.composite(score, parts)

That is all a game needs. Prefer a single self-contained index.html? Paste the ready-to-paste SDK block once in your <head>, without editing it. TypeScript users: get the type definitions.

2. Game lifecycle

const ctx = await WZ.init();      // { mode, competition, seed, attemptsLeft, params, … }
WZ.loading(40);                   // optional: loading progress 0–100
WZ.ready();                       // loaded, the menu is showing

const start = await WZ.gameplayStart();  // the player starts playing
// … during play, optionally every time the score changes:
WZ.progress(score);

await WZ.points(score);           // the game is over

3. Reporting results

WZ.points(1250);                                  // higher is better (most games)
WZ.time(38740);                                   // lower is better, in milliseconds
WZ.composite(total, { points: 950, coins: 15 });  // your own blend, higher is better

Each call returns a promise that resolves once Weezdraw confirmed the result (the SDK resends it automatically until then, and the server counts it only once). WZ.gameOver(score) is an alias of WZ.points. Endless games: call the result when the player stops, and wire a “Done” button to WZ.finish().

4. Fair randomness

In a competition, every player must face the same luck. Use the SDK's random functions instead of Math.random() for anything that affects the game (level layout, enemy spawns, card order…):

WZ.random();            // number in [0, 1)
WZ.randomInt(1, 6);     // integer from 1 to 6
WZ.randomRange(0, 360); // float between 0 and 360

The sequence restarts at each gameplayStart(): every player's first game gets the same numbers, every second game the same other numbers, and so on.

One sequence per part of the game. When several parts of your game draw random numbers, give each its own named sequence: what one part draws (more particles on a fast device, for example) then never shifts another.

const level = WZ.stream("level");
const enemies = WZ.stream("enemies");
level.randomInt(0, 9);        // same for every player
enemies.random();             // independent of the level's draws

Equity is Weezdraw's rule: the SDK also ties Math.random() to the shared seed, so a game that forgot WZ.random still gives every player the same randomness. Using WZ.random or WZ.stream for everything that changes the game remains the right way.

5. Pause and sound

WZ.on("pause",  () => game.pause());
WZ.on("resume", () => game.resume());
WZ.on("mute",   () => audio.mute());
WZ.on("unmute", () => audio.unmute());

If your game handles pause, Weezdraw pauses it when the player leaves the page (a phone call, another app) and resumes it when they come back. Otherwise, in free play, the page stops the game to guarantee silence, and the player loses the game in progress. In a competition the page is never torn down for a short absence, but a game hidden for more than 10 seconds is over (no pause in a competition).

Auto start (SDK 2.1)

In a competition every player must start together, so Weezdraw starts the game itself: it shows your rules and a 3-2-1 countdown while the game loads, then says start. When the context says autoStart, skip your title screen and begin playing on that signal:

const ctx = await WZ.init();
if (ctx.autoStart) {
  WZ.on("start", () => startGame());   // no Play button: Weezdraw starts the game
} else {
  showTitleScreen();                   // free play: the player presses Play
}

A start sent before your game listens is kept until it does. A game that does not listen for start still works: the player presses its Play button.

6. Rules for competitions (required to go live)

7. No-code integration (bridge)

Can't change a game's code (an exported build, a licensed game)? Describe it instead, on your game's page in the developer portal: Weezdraw adds the SDK and a bridge to the page when it is served, and the bridge reports the score for you. The game's files are not modified.

{
  "version": 1,
  "readiness": { "expression": "typeof s_oGame !== 'undefined'" },
  "score":     { "method": "function_hook", "functionPath": "s_oGame.addScore",
                 "argumentIndex": 0, "accumulate": true },
  "gameOver":  { "method": "function_called", "functionPath": "s_oGame.gameOver" },
  "menuSkip":  { "method": "none" },
  "hud":       { "type": "none" }
}

Check it in the preview: the SDK inspector shows what the bridge reports.

8. Testing your game

On your computer: open your index.html. The SDK runs in standalone mode, every call works and resolves at once. Add ?seed=42 to the URL to replay the same random sequence.

In 30 seconds, in your browser: open your index.html (add ?retries=3 to the URL to simulate three allowed games), paste this in the console, and play to the end:

addEventListener("message", (e) =>
  e.data?.type?.startsWith("weezdraw:") && console.log("WZ →", e.data));

Check that: the result matches your game-over screen (for times, metadata.display shows the right seconds); nothing is sent when a life is lost; with ?retries=N the final weezdraw:gameOver comes only after the last game, once, with the best result.

On Weezdraw: after uploading, open Preview from your dashboard. It runs your game in sandbox mode with an SDK inspector listing every call your game makes, so you can check that gameplayStart, progress and the final result are sent at the right moments. Nothing is recorded in sandbox mode.

9. API reference

WZ.init(options?)Promise<context>. Call once at startup.
WZ.loading(percent)Loading progress, 0–100.
WZ.ready()The game is loaded.
WZ.gameplayStart()Promise<{ allowed, attempt, seed }>. The player starts a game.
WZ.progress(score)Live score; also a heartbeat for the server.
WZ.points(score, meta?)Promise. Final result, higher is better.
WZ.time(ms, meta?)Promise. Final result, lower is better.
WZ.composite(score, parts?, meta?)Promise. Final result, higher is better.
WZ.gameOver(score)Alias of WZ.points.
WZ.finish()Ends the session (endless games).
WZ.random() / randomInt(a, b) / randomRange(a, b)Fair random numbers.
WZ.stream(name)An independent fair sequence for one part of the game.
WZ.on(event, fn)pause, resume, mute, unmute, start.
WZ.context / WZ.seed / WZ.versionCurrent context, competition seed, SDK version.

Games written for SDK 1 (the original Weezdraw integration guide: WZ.points, WZ.time, WZ.composite, WZ.gameOver, WZ.finish, ?game= / ?retries=, one weezdraw:gameOver with the best of N) work unchanged with SDK 2. Adding WZ.gameplayStart() and WZ.random() brings server-side counting and fair randomness. Games using the earlier WeezdrawGame SDK (init, reportProgress, gameOver, onPause, onResume) and its URL parameters (gameSlug, gameSeed) work too.

10. Submitting your game

  1. Create a developer account.
  2. Build your game as a ZIP with an index.html (at the root or in one folder) and a poster image.
  3. Choose Submit a game in the developer portal. We check the ZIP and tell you whether the SDK and a result call were found.
  4. Open the preview and check the inspector.
  5. Weezdraw reviews the game. Once approved it goes live; you then see its plays and your earnings.