SharedStorage
Older API, still supported and not going away. New decks should use
Storeinstead.SharedStoragehas no ownership rule — any player can overwrite any key in the'deck'bucket — and two players writing at the same moment lose one of the writes.Storefixes both, and adds counters, listing, and leaderboards.
SharedStorage saves data that other players can read. Values must be
something that converts to JSON, same as Storage. Each bucket holds at
most 2 MB, and a write past that is dropped without an error, as with
Storage.
Scopes: 'deck' is one bucket for the whole deck, readable and writable
by any player. 'user' is a per-player bucket that anyone can read and
only the owning player can write.
SharedStorage.get(scope, key)— reads a shared value. For'user', pass a user id before the key to read someone else's bucket.SharedStorage.set(scope, key, value)— writes.'user'writes always go to the current player.SharedStorage.remove(scope, key)— removes a shared value.
const worldHighScore = await SharedStorage.get("deck", "highScore");
const theirColor = await SharedStorage.get("user", otherUserId, "color");
SharedStorage.set("user", "color", "red");
The same thing with Store:
const { highScore } = await Store.deck.get(["highScore"]);
const { color } = await Store.user(otherUserId).get(["color"]);
await Store.me.set({ color: "red" });