Add achievements and high scores to a web game once and have them work on every site. Newgrounds medals and scoreboards, Game Jolt trophies and score tables, CrazyGames gameplay signals, and a local fallback everywhere else (Bash, itch.io, GitHub Pages, your own site). One small drop-in script (assets/achievements.js) detects where the game is running. Use for "add achievements", "medals", "tro...
Download skill (.zip) Files on GitHubAchievements and scores on every site
assets/achievements.js has no dependencies. Copy it into the game (for example
www/vendor/achievements.js) and call one API. Where it’s running decides what happens:
| Running on | unlock("key") |
submitScore("key", n) |
Extra |
|---|---|---|---|
| Newgrounds | Medal unlock (official NewgroundsIO lib, loaded on demand) | Scoreboard post | Player must be signed in to Newgrounds |
| Game Jolt | Trophy achieved | Score table entry | Signed-in player comes from the page URL (gjapi_username / gjapi_token) |
| CrazyGames | Saved locally + happytime() |
Saved locally | gameplayStart/Stop, loadingStart/Stop |
| Anywhere else | Saved locally | Best score saved locally | Works in the Bash preview and on itch.io |
Unlocks are always saved locally too, so isUnlocked(), list(), and the onUnlock toast
(shown once) work the same everywhere. Nothing throws: if a site is down or the player isn’t signed
in, the game keeps playing.
Inside Bash only? Bash spaces have their own leaderboards and saves (see the game kit / playing-together skills). This skill is for games published to other sites.
1. Add it
<script src="./vendor/achievements.js"></script>
const ach = await Achievements.init({
gameId: "my-game", // local save prefix
version: "1.0.0",
achievements: { // names shown in toasts / the list screen
firstWin: { title: "First Win", description: "Win your first round" },
speedster: { title: "Speedster", description: "Finish in under 30 s" },
},
scores: { highScore: {}, bestTime: { lowerIsBetter: true, format: v => (v / 1000).toFixed(2) + " s" } },
onUnlock: (key, a) => showToast(`🏆 ${a.title}`), // game-drawn toast; keep it small, 2–3 s
newgrounds: { appId: "12345:AbCdEfGh", aesKey: "…==", medals: { firstWin: 81234 }, boards: { highScore: 14567 } },
gamejolt: { gameId: 123456, privateKey: "…", trophies: { firstWin: 98765 }, tables: { highScore: 54321 } },
crazygames: true,
});
ach.unlock("firstWin");
ach.submitScore("highScore", score); // returns true if it's a new local best
ach.gameplayStart(); /* … */ ach.gameplayStop(); // call around actual play (CrazyGames ranks on this)
Leave out any platform the user hasn’t set up. Its section just isn’t used.
init waits at most 3 seconds, so it can run during the loading screen. Don’t block the title screen on it.
2. Get the IDs from the user
Never invent IDs. Ask for them, or point the user to the human guides:
| Platform | Where the values are | Guide |
|---|---|---|
| Newgrounds | Project → API Tools: App ID, AES-128 / Base64 encryption key, medal and scoreboard IDs | docs/services/newgrounds.md |
| Game Jolt | Game → Game API → API Settings: Game ID, private key; Trophies / Scoreboards IDs | docs/services/game-jolt.md |
| CrazyGames | Nothing to configure. The SDK loads itself on CrazyGames | docs/services/crazygames.md |
These keys ship inside the game. That’s how both APIs are designed for web games, so they’re not Bash secrets and are fine to paste in chat. Tell the user medals and scores can be faked by determined players, and treat them as “for fun”.
3. In-game UI
- Toast: a small panel that slides in at the top for 2–3 s, drawn by the game (no
alert). - Achievements screen:
ach.list()returns[{ key, title, description, unlocked, at }]. Show locked ones greyed out, and hide secret ones until unlocked. - Best score:
ach.best("highScore"). - Newgrounds sign-in (optional): if
ach.platform === "newgrounds" && !ach.user, show a “Sign in to save medals” button that callsach.login(). It must be a click, because popups are blocked otherwise.
4. Test
index.html?platform=local # default outside the portals
index.html?platform=gamejolt&gjapi_username=test&gjapi_token=test # exercises the Game Jolt calls
Pass debug: true in the config to log every call ([achievements] ...) and check read_preview_console.
Real medals and trophies can only be confirmed on the live site with a signed-in account. Tell the user
to try one unlock after uploading.
Notes
- CrazyGames has no achievements API. Unlocks are local, and each one also triggers
happytime()(a positive signal). CrazyGames requires its SDK for Full Launch:crazygames: trueplusgameplayStart/Stopcovers it. - The Newgrounds library is loaded from a pinned jsDelivr copy. To bundle it instead, download
NewgroundsIO.min.jsintowww/vendor/and setnewgrounds.libUrl: "./vendor/NewgroundsIO.min.js". ach.resetLocal()clears local unlocks and bests, for a “reset progress” button.