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.
Keys are simple string-based variables tied to a player. They allow you to:
These are not paragraph-local. They persist globally per player.
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.
if (!get_key("intro_seen")) {
print("Welcome, stranger! This must be your first time here.\n");
set_key("intro_seen", "yes");
}
if (get_key("spoke_to_hermit") === "true") {
print("The hermit gives you a knowing look.\n");
}
let times = parseInt(get_key("fished_here") || "0");
times++;
set_key("fished_here", String(times));
๐ You can track visit counts, number of wins, etc.
delete_key()
where appropriate.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.