Skip to main content

Players in Games on Arcadible

Your game runs for one player: someone logged in to Arcadible, or a guest. arcadible.players.primary says who, with an id that's theirs in your game, whether they're a guest, and their name. arcadible.players.pictures() gives their picture, when you want to draw it.

await arcadible.initStart();
const player = arcadible.players.primary;
if (player) {
greeting.textContent = player.name ? `Welcome back, ${player.name}` : "Welcome";
}

Nothing asks the player first: a game is given no more than Arcadible already shows of them, and less. You don't need any of it to keep their progress, which saves already do, for each player.

Who's playing​

arcadible.players.primary is the player your game runs for, set once initStart() has resolved, and the same for the whole run.

FieldValue
idThis player in your game: a UUID, the same every time they play it, different in every game
guesttrue when they aren't logged in: a guest plays on this device, with no account
nameTheir name, as Arcadible shows it; null for a guest, or a player with none
  • It never changes under your game. When a player logs out, or someone else logs in, Arcadible pauses your game, so it saves, and starts it again for them. There's nothing to listen for.
  • Off Arcadible it's null, such as on your own dev server: no one says who's playing. arc serve runs your game for a guest.
  • A guest is a device. A guest's id is kept in the browser or the Arcadible app they play in, so the same person is another guest somewhere else, and after clearing their browser's data.

The id​

Key what you keep about a player on id. It's the same on every run, version, and device for a player who's logged in.

  • It's yours alone. The same player has a different id in every game, so two games can't tell they share a player, and it isn't their Arcadible handle or account.
  • It isn't proof. Anyone can send your server any id, so don't trust one with anything that matters, such as a purchase or a ranked score. Arcadible doesn't yet give a game's server a way to check who's playing.
  • Don't key saves on it. Arcadible already keeps each player's saves apart: a save your game writes is the player's it runs for, and a guest who logs in keeps what they'd saved.

The name​

A name is the player's own words. Show it as text, never as HTML.

label.textContent = player.name ?? (player.guest ? "Guest" : "Player"); // never innerHTML
  • It can be anything a player types: long, in any script, with emoji. Give it room, and cut it off with an ellipsis rather than breaking your layout.
  • It can be null, for a guest and for a player who hasn't set one. Have words of your own ready, one for each: someone logged in with no name isn't a guest.
  • It's as it was when the run started. A player who renames themselves is their new name the next time they play.

Pictures​

Ask for a picture when you draw one, with arcadible.players.pictures(). It takes players, or their ids, and resolves with one entry for each, in the same order: a Blob, or null for a player with no picture, as a guest always is.

const [picture] = await arcadible.players.pictures([arcadible.players.primary]);
if (picture) {
const bitmap = await createImageBitmap(picture);
context.drawImage(bitmap, 0, 0, 64, 64);
}
  • A WebP image, 256 × 256, square, to draw at any size up to that. As an <img>, give it URL.createObjectURL(picture), and revoke the URL when you're done.
  • It's an image, not an address, so drawing it never taints your canvas, and there's nothing to keep that goes stale: ask again next run.
  • It needs the network. Offline, the call rejects with unavailable: draw your own placeholder, and try again later.
  • Up to 50 players a call. Today a game knows one player, its own.

What a game isn't given​

  • No handle, email, or account. Nothing a game is given is the same in another game.
  • No log-in or log-out. Players log in with Arcadible, not with your game, and your game doesn't offer it.
  • No list of friends or other players yet.

Without the SDK, and off Arcadible​

  • Without the SDK, your game doesn't know who's playing. Its saves, if it has none of Arcadible's, are its own browser storage.
  • Off Arcadible, arcadible.players.primary is null and every picture is null. Write your game so it plays without a player: arcadible.players.primary?.name ?? "Player".

Trying it​

arc serve runs your game for a guest, with an id it keeps between runs. To see a logged-in player, with a name and a picture, deploy a prerelease and play it logged in (Testing Your Game).

Checklist​

  • Plays the same for a guest, a player with no name, and off Arcadible, where there's no player
  • Shows a name as text, never as HTML, and gives a long one room
  • Keys nothing that matters on an id alone
  • Draws its own placeholder when there's no picture, or no network

Next steps​

  • arcadible.players: every member, exactly.
  • Saves: each player's progress, kept for them.
  • Pausing: what your game does before Arcadible restarts it for another player.