Secret Codes
Give every player their own code, reveal it in one game and check it on the server from any game.
A secret code is a puzzle piece the player has to go and find. One game reveals it, the same game or another one asks for it, and Remix checks the guess on the server. Every player has their own code, so a code shared online opens nothing for anyone else, and no game ships it, so reading a page never gives it away.
Use codes for a door in one world that opens with a number found in another, a lock whose combination is written somewhere else in the same game, or any riddle whose answer should be earned rather than looked up.
How a Code Is Named
A code belongs to the game that reveals it and has a short name, such as lantern or north-sigil. Remix derives each player's code from those two, the format and the player, so there is nothing to declare and nothing to store: using a name creates it.
A code is eight characters from an unambiguous alphabet (no I, O, 0 or 1) unless you ask for digits. Pass { digits: 4 } (4 to 12) for dials and keypads. The game that reveals a code and the game that checks it must pass the same format.
Revealing a Code
Only a game can reveal its own codes. Show the result where the player finds it:
const result = await sdk.codes.reveal('lantern', { digits: 4 })
if (result?.ok) showOnLantern(result.code) // '7294', different for every player
Reveal the code only once the player has earned it in your game, for example when they carry the light to the lantern. The game decides when; Remix only makes sure the code is this player's and that no other game can ask for it.
Checking a Guess
Any game can check any game's code. Pass the catalog id of the game that reveals it, or leave game out to check one of your own:
// The catalog id of the game that reveals the code, from its game page.
const CASTLE_GAME_ID = 'your-other-game-id'
const result = await sdk.codes.check('lantern', dials.join(''), {
game: CASTLE_GAME_ID,
digits: 4,
})
Case, spaces and dashes in the guess never matter. Check when the player commits to a guess (a "Try the lock" button, Enter), never on every dial turn or keystroke: each wrong check counts.
Wrong Guesses and Cooldowns
Remix paces wrong guesses per player and per code, so trying every combination takes days rather than minutes:
- Three wrong guesses inside ten seconds rest the code for one minute.
- Twenty wrong guesses in an hour rest it until that hour is out.
- A right guess never counts, and a guess sent while the code rests is not checked at all.
These are answers to show the player, not errors. Every result carries a reason you can display as is, or write your own:
if (result === null) showMessage('The lock is silent. Try again later.')
else if (result.ok) openChest()
else if (result.code === 'wrong') showMessage(`Wrong code. ${result.triesLeft} tries left.`)
else if (result.code === 'cooldown') lockDials(result.retryAfterSeconds, 'The code is in the castle. Go and find it.')
else showMessage(result.reason)
| Result | Meaning |
|---|---|
{ ok: true } | The guess is this player's code. |
wrong | Not the code. triesLeft wrong guesses remain before a cooldown. |
cooldown | Too many wrong guesses. retryAfterSeconds until the next guess is checked. |
invalid | A malformed name, format or game id. |
throttled | Too many code requests from this game or player. |
unavailable | Remix could not answer now. Try again later. |
null | A guest, or a host that predates codes. |
Rules
- Never put a code, a hash of one or a check for one in your game. Remix holds every code.
- Guests have no code: both calls resolve
null. Offer a sign-in prompt or let them skip the puzzle. - Reveal and check are separate from achievements. If opening the lock should also earn an achievement, unlock it after
checkanswersok. - In Remix Desktop's preview, codes are made up for the session. Checking another game's code prints that preview code to the console, so you can test the whole flow before publishing.