Skip to main content

SaveSlotExportUtils

Pure helpers describing an exported save slot and the main-slot guard that keeps export/import away from the player's shared root datastore. See HasSaveSlots.PromiseExportSlot and HasSaveSlots.PromiseImportSlot.

Types

SaveSlotExportKind

interface SaveSlotExportKind {
CODE"code"--

a share code, redeemable into a slot the owner keeps

TRANSFER"transfer"--

a live snapshot carried across a teleport, loadable from a client-presented key

}

What an entry in the shared store may be loaded as.

The two exist because one of the shared store's readers takes its key from the client: a teleport arrives carrying the key of the transferable ephemeral slot it is resuming, and the arrival path loads whatever is behind it. A share code handed to a friend must not be loadable that way, so the writer records which of the two it wrote and each reader accepts only its own kind.

Functions

isMainSlotIndex

SaveSlotExportUtils.isMainSlotIndex(slotIndexnumber) → boolean

Returns whether the given index is the main/default slot -- the one whose store is the player's shared root datastore (it shares that key with the SaveSlots system data and universe-scoped global data). Export/import refuse this index in both directions.

isSaveSlotExport

SaveSlotExportUtils.isSaveSlotExport(valueany) → boolean

Returns whether the value is a well-formed [SaveSlotExport].

canLoadAs

SaveSlotExportUtils.canLoadAs(
exportSaveSlotExport,
) → boolean

Returns whether an entry read from the shared store may be loaded as the given kind.

Entries written before kinds existed carry none, and are treated as share codes: back then the transfer path re-saved under the very key the code was minted as, so an untagged entry is indistinguishable from the code it started life as. Old codes therefore keep working, while the arrival path -- the one reading a client-presented key -- accepts nothing that was not explicitly written as a transfer.

withKind

SaveSlotExportUtils.withKind(
exportSaveSlotExport,
) → SaveSlotExport

Returns a copy of the export tagged as the given kind, for writing to the shared store.

create

SaveSlotExportUtils.create(
data{[string]any},
slotNamestring?,
summaryany?,
timePlayednumber?--

the source slot's accrued playtime, in seconds

) → SaveSlotExport

Builds a [SaveSlotExport] from a slot's data table and its metadata.

Show raw api
{
    "functions": [
        {
            "name": "isMainSlotIndex",
            "desc": "Returns whether the given index is the main/default slot -- the one whose store is the player's\nshared root datastore (it shares that key with the SaveSlots system data and universe-scoped\nglobal data). Export/import refuse this index in both directions.",
            "params": [
                {
                    "name": "slotIndex",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 59,
                "path": "src/saveslot/src/Shared/SaveSlotExportUtils.lua"
            }
        },
        {
            "name": "isSaveSlotExport",
            "desc": "Returns whether the value is a well-formed [SaveSlotExport].",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 69,
                "path": "src/saveslot/src/Shared/SaveSlotExportUtils.lua"
            }
        },
        {
            "name": "canLoadAs",
            "desc": "Returns whether an entry read from the shared store may be loaded as the given kind.\n\nEntries written before kinds existed carry none, and are treated as share codes: back then the\ntransfer path re-saved under the very key the code was minted as, so an untagged entry is\nindistinguishable from the code it started life as. Old codes therefore keep working, while the\narrival path -- the one reading a client-presented key -- accepts nothing that was not explicitly\nwritten as a transfer.",
            "params": [
                {
                    "name": "export",
                    "desc": "",
                    "lua_type": "SaveSlotExport"
                },
                {
                    "name": "kind",
                    "desc": "",
                    "lua_type": "SaveSlotExportKind"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 105,
                "path": "src/saveslot/src/Shared/SaveSlotExportUtils.lua"
            }
        },
        {
            "name": "withKind",
            "desc": "Returns a copy of the export tagged as the given kind, for writing to the shared store.",
            "params": [
                {
                    "name": "export",
                    "desc": "",
                    "lua_type": "SaveSlotExport"
                },
                {
                    "name": "kind",
                    "desc": "",
                    "lua_type": "SaveSlotExportKind"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "SaveSlotExport"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 120,
                "path": "src/saveslot/src/Shared/SaveSlotExportUtils.lua"
            }
        },
        {
            "name": "create",
            "desc": "Builds a [SaveSlotExport] from a slot's data table and its metadata.",
            "params": [
                {
                    "name": "data",
                    "desc": "",
                    "lua_type": "{ [string]: any }"
                },
                {
                    "name": "slotName",
                    "desc": "",
                    "lua_type": "string?"
                },
                {
                    "name": "summary",
                    "desc": "",
                    "lua_type": "any?"
                },
                {
                    "name": "timePlayed",
                    "desc": "the source slot's accrued playtime, in seconds",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "SaveSlotExport"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 135,
                "path": "src/saveslot/src/Shared/SaveSlotExportUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "SaveSlotExportKind",
            "desc": "What an entry in the shared store may be loaded as.\n\nThe two exist because one of the shared store's readers takes its key from the client: a teleport\narrives carrying the key of the transferable ephemeral slot it is resuming, and the arrival path\nloads whatever is behind it. A share code handed to a friend must not be loadable that way, so the\nwriter records which of the two it wrote and each reader accepts only its own kind.",
            "fields": [
                {
                    "name": "CODE",
                    "lua_type": "\"code\"",
                    "desc": "a share code, redeemable into a slot the owner keeps"
                },
                {
                    "name": "TRANSFER",
                    "lua_type": "\"transfer\"",
                    "desc": "a live snapshot carried across a teleport, loadable from a client-presented key"
                }
            ],
            "source": {
                "line": 30,
                "path": "src/saveslot/src/Shared/SaveSlotExportUtils.lua"
            }
        }
    ],
    "name": "SaveSlotExportUtils",
    "desc": "Pure helpers describing an exported save slot and the main-slot guard that keeps export/import\naway from the player's shared root datastore. See [HasSaveSlots.PromiseExportSlot] and\n[HasSaveSlots.PromiseImportSlot].",
    "source": {
        "line": 9,
        "path": "src/saveslot/src/Shared/SaveSlotExportUtils.lua"
    }
}