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
| SharedVariables | SharedStorage | |
|---|---|---|
| Persistence | Session only | Across sessions |
| Use case | Runtime signals, temp flags | Permanent shared data |
| Performance | Faster (in-memory) | Disk-backed |
