Game SDK (AIGame)
Every published game automatically gets a small SDK (window.AIGame). Nothing to install.
Leaderboards
Call submitScore and a leaderboard appears on the game page. Each logged-in player's personal best is kept.
js
// On game over
window.AIGame?.submitScore(score);
// Record a time (lower is better)
window.AIGame?.submitScore(seconds, { order: "asc", label: "sec" });
// Multiple leaderboards
window.AIGame?.submitScore(score, { board: "hard", label: "Hard" });
// Get the result
const result = await window.AIGame?.submitScore(score);
// => { ok: true, rank: 3, best: 1200 } / { ok: false, reason: "login_required" }What to tell your AI
Give the game a score. On game over call window.AIGame?.submitScore(score) (use ?. so it doesn't fail where AIGame is missing). For time attacks use window.AIGame?.submitScore(seconds, { order: "asc" }).
Other features
AIGame.gameOver({ score }): signals game over (used for “next game” prompts in play mode).- Errors and console output are forwarded to the page and shown in a console only the creator sees.
- For thumbnail capture, WebGL's preserveDrawingBuffer is enabled automatically.
- Arrow keys and space no longer scroll the page.
Runtime environment
- Each game runs on its own domain ({gameId}.play…). localStorage is per game and isolated from other games and the main site.
- Games run inside an iframe and cannot navigate the top page. Open links in a new tab.
- External CDNs and APIs can be used.
