ssod

Game Keys and Persistent Flags

The set_key, get_key, and delete_key functions provide a powerful way for content creators to track custom state across a playerโ€™s entire game session. These values are persistent, meaning they are stored in the database and remembered between sessions.

๐ŸŽฏ Use keys to store custom flags, counters, or variables for each player.


๐Ÿ”‘ What Are Keys?

Keys are simple string-based variables tied to a player. They allow you to:

These are not paragraph-local. They persist globally per player.


๐Ÿ› ๏ธ Functions

set_key(key, value)

Sets a key to a string value.

set_key("hideout_unlocked", "true");

๐Ÿ” Keys can only store strings. Convert numbers to strings with String(value) if needed.


get_key(key)

Retrieves the stored string value for a key.

if (get_key("hideout_unlocked") === "true") {
  print("You return to the hideout entrance.");
}

Returns undefined if the key has never been set.


delete_key(key)

Removes a key permanently.

delete_key("hideout_unlocked");

Useful for resetting state or allowing repeatable choices.


๐Ÿ“˜ Use Cases

๐Ÿ“ Custom Flags

if (!get_key("intro_seen")) {
  print("Welcome, stranger! This must be your first time here.\n");
  set_key("intro_seen", "yes");
}

๐Ÿ” Optional Paths

if (get_key("spoke_to_hermit") === "true") {
  print("The hermit gives you a knowing look.\n");
}

โ™ป๏ธ Repeatable Events

let times = parseInt(get_key("fished_here") || "0");
times++;
set_key("fished_here", String(times));

๐Ÿ”Ž You can track visit counts, number of wins, etc.


โš ๏ธ Limitations & Best Practices


If you want to store temporary, time-limited flags, consider using <tempset> instead. For global story flags shared across all players, use set_global() (via tag).


Return to the JavaScript Scripting Guide or continue with the Achievement Key Functions.