Manages persistent storage of data with automatic serialization

interface Player {
name: string;
inventory: string[];
health: number;
}

const playerData = new PersistedStore<Player>("player", {
name: "Steve",
inventory: [],
health: 20
});

// Load saved data
playerData.load();

// Update and save
playerData.value.inventory.push("diamond");
playerData.save();

Type Parameters

  • T extends any

    Type of data being stored

Constructors

Properties

Methods

Constructors

  • Type Parameters

    • T extends unknown

    Parameters

    • name: string
    • defaultValue: T
    • Optionalserializer: Serializer<any>

    Returns PersistedStore<T>

Properties

name: string

Creates a new persistent store

Filename to store data in (under /persisted/)

Initial value if no data exists

Optional custom serializer (defaults to textutils)

If file operations fail

value: T

Methods

  • Loads saved value from disk If no saved data exists, keeps the default value

    Returns void

  • Saves current value to disk

    Returns void

    If file write fails