Skip to main content

SaveSlotCodeUtils

Generates human-sanity-checkable share codes for exported save slots, and defines the injectable generator a game overrides via SaveSlotService.SetCodeGenerator. The default format, <date>-<state>-<user>-<token> (e.g. 20260723-world3-jonnen-4f7k2q1a), is recognizable on copy/paste -- you can eyeball the date, slot, and owner -- while the random token keeps it collision-resistant. Codes are used as datastore keys, so every component is sanitized to a safe, length-capped lowercase slug.

Types

CodeGeneratorContext

interface CodeGeneratorContext {
userIdnumber?
userNamestring?
slotNamestring?
slotIndexnumber?
}

The information a code generator may fold into a code. Every field is optional -- a generator must degrade gracefully when, say, the player's user id cannot be resolved.

CodeGenerator

type CodeGenerator = (CodeGeneratorContext) → string

Produces a share code from the context. Injected per game via SaveSlotService.SetCodeGenerator.

Functions

generateDefaultCode

SaveSlotCodeUtils.generateDefaultCode(contextCodeGeneratorContext) → string

The default share-code generator: <date>-<state>-<user>-<token>.

Show raw api
{
    "functions": [
        {
            "name": "generateDefaultCode",
            "desc": "The default share-code generator: `<date>-<state>-<user>-<token>`.",
            "params": [
                {
                    "name": "context",
                    "desc": "",
                    "lua_type": "CodeGeneratorContext"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 63,
                "path": "src/saveslot/src/Shared/SaveSlotCodeUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "CodeGeneratorContext",
            "desc": "The information a code generator may fold into a code. Every field is optional -- a generator must\ndegrade gracefully when, say, the player's user id cannot be resolved.",
            "fields": [
                {
                    "name": "userId",
                    "lua_type": "number?",
                    "desc": ""
                },
                {
                    "name": "userName",
                    "lua_type": "string?",
                    "desc": ""
                },
                {
                    "name": "slotName",
                    "lua_type": "string?",
                    "desc": ""
                },
                {
                    "name": "slotIndex",
                    "lua_type": "number?",
                    "desc": ""
                }
            ],
            "source": {
                "line": 28,
                "path": "src/saveslot/src/Shared/SaveSlotCodeUtils.lua"
            }
        },
        {
            "name": "CodeGenerator",
            "desc": "Produces a share code from the context. Injected per game via [SaveSlotService.SetCodeGenerator].",
            "lua_type": "(CodeGeneratorContext) -> string",
            "source": {
                "line": 41,
                "path": "src/saveslot/src/Shared/SaveSlotCodeUtils.lua"
            }
        }
    ],
    "name": "SaveSlotCodeUtils",
    "desc": "Generates human-sanity-checkable share codes for exported save slots, and defines the injectable\ngenerator a game overrides via [SaveSlotService.SetCodeGenerator]. The default format,\n`<date>-<state>-<user>-<token>` (e.g. `20260723-world3-jonnen-4f7k2q1a`), is recognizable on\ncopy/paste -- you can eyeball the date, slot, and owner -- while the random token keeps it\ncollision-resistant. Codes are used as datastore keys, so every component is sanitized to a safe,\nlength-capped lowercase slug.",
    "source": {
        "line": 12,
        "path": "src/saveslot/src/Shared/SaveSlotCodeUtils.lua"
    }
}