Skip to content

Storage (soft memory)

Storage is a simple key‑value store your script can read and write — counters, flags, "have I seen this player," small bits of state. It's soft memory: fast, in‑memory, and scoped to your script.

int visits = Storage.GetInt("visits", 0) + 1;
Storage.SetInt("visits", visits);

Storage.SetString("last_winner", playerName);
string who = Storage.GetString("last_winner", "nobody");

API

Call Returns
Storage.SetString(key, value) / GetString(key, default = "") string
Storage.SetInt(key, value) / GetInt(key, default = 0) int
Storage.SetFloat(key, value) / GetFloat(key, default = 0) float
Storage.HasKey(key) bool
Storage.DeleteKey(key) / Storage.DeleteAll()

What "soft" means — read this

In‑memory, per‑instance — lost on restart

Storage lives in RAM on the running world instance. It is not saved to disk.

  • ✅ A player who leaves and rejoins while the instance is up is remembered.
  • ❌ When the world instance restarts (or empties out and shuts down), Storage is wiped.

So it's perfect for "this session" — scores, round state, who's here now — but not for anything that must survive a restart.

It's also sandboxed per script class: each NexusScript gets its own isolated store, so two scripts can't read each other's keys (no accidental collisions). Limits: 256 keys per script, 4 KB per value.

When you need it to last — durable storage

For anything that must persist across restarts (visit counts, rewards, progression, leaderboards), write to your own database with the HTTP / Supabase API, keyed by the player's stable account id (Player.GetUserId):

string userId = Player.GetUserId(playerId);   // stable across sessions
// Http.* → POST/PATCH a row keyed by userId  (see the HTTP page)

A common pattern is both: Storage as a fast cache for the current session, your DB as the durable record.

Example — returning‑visitor greeting

string userId = Player.GetUserId(playerId);
if (userId != "")
{
    int visits = Storage.GetInt("visits_" + userId, 0) + 1;
    Storage.SetInt("visits_" + userId, visits);
    NPC.Notify("player_entered",
        "{\"visit\": \"" + (visits == 1 ? "first" : "returning") + "\"}");
}

The NPC can now say "Hello there!" vs "Welcome back!" — without ever speaking a name. (Within‑session here; swap the counter to your DB to make it survive restarts.) Full version: the IdentityGreeter example.