Skip to content

sup.global

The sup.global package provides methods for storing and retrieving global state that persists across all patch runs on Sup. It is accessed through sup.global.

Example sup.global Usage
// Store global data
sup.global.set("totalUsers", 1000);
sup.global.set("lastUpdate", new Date());
// Retrieve global data
const totalUsers = sup.global.get("totalUsers");
const lastUpdate = sup.global.get("lastUpdate");

Methods

sup.global.set()

(key: string, value: any) → void

sup.global.set("totalGames", 100);
sup.global.set("highScores", [
{ name: "player1", score: 1000 },
{ name: "player2", score: 950 }
]);

Sets a key-value pair in the patch’s global state.

The key can be any string, and the value can be any JSON-serializable object (including Sup classes like User, Image, Message, etc.).

Global state is shared across all patch runs on the Sup platform, regardless of chat or user.

sup.global.get()

(key: string) → any | null

const totalGames = sup.global.get("totalGames"); // 100
const scores = sup.global.get("highScores"); // [{ name: "player1", score: 1000 }, ...]

Retrieves the value of a key from the patch’s global state.

If the key does not exist, get returns null.

Global state is useful for storing platform-wide data like:

  • Total usage statistics
  • Cross-chat leaderboards
  • Global settings or configurations
  • Shared resources or assets

sup.global.keys()

→ string[]

const keys = sup.global.keys(); // ["totalGames", "highScores", ...]

Returns an array of all keys stored in the patch’s global state.

Keys that have been set() during the current patch run are included in the results, even before they are persisted to the database.