Skip to content

Saving data

Persistent data for experiences: a player’s save, a shared world, a leaderboard – kept between sessions and server restarts. Server scripts only; the manifest declares the data capability.

scripts/server/main.js
const farmers = gdmp.data.getStore("farmers"); // JSON values
const best = gdmp.data.getOrderedStore("best-farmers"); // numbers, sorted
gdmp.players.onSpawn(async p => {
const key = "name:" + p.name;
const save = (await farmers.get(key)) || { gold: 500 };
// ... play ...
await farmers.set(key, save);
await best.set(key, save.gold);
const top = await best.top(10); // { entries: [{ key, value, rank }], cursor }
});
getStore(name) → store name: 1..64 characters of A-Z a-z 0-9 _ - .
store .get(key) → value | null a fresh copy of what was stored
store .getEntry(key) → {value, version, updated, users} | null
store .set(key, value[, {ifVersion, users}]) → {version, updated} ifVersion: write only if the key is at that version (0 = only if it does not exist yet). users: whose data this is (so it can be erased on request)
store .update(key, fn[, {users}]) → the new value read-modify-write: fn(old, {version} | null) returns the new value (undefined = change nothing). If another server wrote in between, fn runs again on the newer value (up to 5 times)
store .increment(key[, step = 1]) → the new number atomic
store .remove(key[, {ifVersion}]) → existed (bool)
store .list({prefix, cursor, limit}) → {keys: [{key, version, updated}], cursor} keys in order, 1..100 a page; cursor (null at the end) gets the next page
getOrderedStore(name) → ordered store get set increment remove (finite numbers only)
ordered .top(limit = 10[, {ascending, cursor}]) → {entries: [{key, value, rank}], cursor} largest first unless ascending
ordered .rank(key[, {ascending}]) → rank | null 1 = the best; ties share the better rank
status() → {backend, environment, ...} local / hub; local, dev or live

Every method returns a Promise. A wrong argument (a bad key, a value JSON cannot hold, a value over 256 KB) is a TypeError at once. Anything the service refuses rejects with an Error whose code says why:

code
RATE_LIMITED a budget is spent; error.retryAfterMs says when to try again
CONFLICT ifVersion did not match (another write came first)
TOO_LARGE / QUOTA a value over 256 KB / the experience’s data is full
NOT_A_NUMBER increment on a key that is not a number; an ordered store given something else
UNAVAILABLE the service cannot be reached right now
FORBIDDEN, BAD_KEY, BAD_STORE, BAD_REQUEST, INTERNAL

Keys: 1..128 printable ASCII characters, no leading or trailing space. Values: anything JSON.stringify can write, at most 256 KB as JSON.

Per experience server, per minute:

per minute
reads (get, getEntry) 60 + 10 × players
writes (set, update’s write, increment, remove) 60 + 10 × players
lists (list, top, rank) 10 + 2 × players
one key one write per second
waiting at once 256 requests

The budgets refill continuously and hold up to one minute’s worth.

  • On your PC (the launcher’s local play): a folder next to the server. Good for testing.
  • On GDMP (a published experience): on the GDMP hub. The hub keeps two separate environments:
    • live: the server runs the published version of your experience;
    • dev: any other version (your tests). Test data never touches what players have.

The owner of an experience can create API keys (gdk_<id>.<secret>) for their own tools: scopes read, write, list, delete, for live, dev or both, optionally only for stores starting with a prefix. A key is shown once and can be revoked. Players can never reach the data: a client script has no gdmp.data.