Skip to content

SharedVariables

The SharedVariables namespace provides in-memory key-value storage shared between all mods. Data is lost when the game is closed (session-only). All mods read and write to the same key space.

For persistent shared storage, use SharedStorage. For mod-private session variables, use Variables.

No permission required.

Import

typescript
import { SharedVariables } from "@hotbunny/hackhub-content-sdk";

Methods

SharedVariables.get<T>(key)

Get a shared variable by key. Returns undefined if not found.

Returns: T | undefined

typescript
const difficulty = SharedVariables.get<string>("globalDifficulty");

SharedVariables.set(key, value)

Set a shared variable by key.

typescript
SharedVariables.set("globalDifficulty", "hard");

SharedVariables.remove(key)

Remove a shared variable.

typescript
SharedVariables.remove("globalDifficulty");

SharedVariables.getAll()

Get all shared variables.

Returns: Record<string, any>

Use Cases

Runtime inter-mod communication

typescript
// Mod A: Signal that a boss fight is active
SharedVariables.set("bossfight-mod.isActive", true);
SharedVariables.set("bossfight-mod.bossHp", 1000);

// Mod B: React to the boss fight
if (SharedVariables.get<boolean>("bossfight-mod.isActive")) {
    // Disable certain features during boss fight
}

Shared game state

typescript
// Any mod can read/write the global difficulty
SharedVariables.set("game.difficulty", "nightmare");
const diff = SharedVariables.get<string>("game.difficulty");

Key Naming Convention

Use a prefix to avoid collisions between mods:

{mod-id}.{key-name}

SharedVariables vs SharedStorage

SharedVariablesSharedStorage
PersistenceSession onlyAcross sessions
Use caseRuntime signals, temp flagsPermanent shared data
PerformanceFaster (in-memory)Disk-backed

HotBunny Interactive Entertainment Inc.