# `Save` API {#save-api}

Note: There are several configuration settings for saves that it would be wise for you to familiarize yourself with.

Warning: Browser saves—i.e., auto and slot saves—are largely incompatible with private browsing modes, which cause all in-browser storage mechanisms to either persist only for the lifetime of the browsing session or fail outright.

## Save Objects {#save-api-objects} ### Save Data {#save-api-objects-data}

Note: Adding additional properties directly to save data objects is not recommended. Instead, use the metadata property.

#### Save Data Object A save data object has the following properties: * **`date`:** (`integer`) The save's creation date (in milliseconds elapsed since epoch). * **`desc`:** (`string`) The save's description. * **`id`:** (`string`) The save ID. See the [`Config.saves.id`](#config-api-property-saves-id) for details. * **`metadata`:** (optional, `any`) The save's metadata, which *must* be JSON-serializable. Exists only if specified. See the appropriate save API or [`Config.saves.metadata`](#config-api-property-saves-metadata) for details. * **`state`:** (`object`) The marshaled story state. See below for details. * **`type`:** (`Save.Type`) The save's type. See [`Save.Type`](#save-api-constants-type) for details. * **`version`:** (optional, `any`) The save's version. Exists only if specified. See [`Config.saves.version`](#config-api-property-saves-version) for details. #### Save State Object The marshaled story state object, from the **`state`** property, has the following properties: * **`expired`:** (optional, `Array`) The array of expired moment passage titles. Exists only if any moments have expired. * **`history`:** (`Array`) The array of moment objects. See below for details. * **`index`:** (`integer`) The index of the active moment. * **`seed`:** (optional, `string`) The seed of the seedable PRNG. Exists only if enabled. #### Save History Moment Objects Each moment object, from the **`history`** property's array, has the following properties: * **`pull`:** (optional, `integer`) The current pull count of the seedable PRNG. Exists only if enabled. * **`title`:** (`string`) The name of the associated passage. * **`variables`:** (`object`) The current variable store object, which contains sigil-less name ⇒ value pairs—e.g., `$foo` exists as the property `foo`. ### Save Descriptor {#save-api-objects-descriptor} Save descriptor objects are only provided for browser saves and are identical to [save data objects](#save-api-objects-data) save that they do not include a `state` property ## Constants {#save-api-constants} ### `Save.Type` {#save-api-constants-type} Save types pseudo-enumeration. Used to denote the type of save. #### History: * `v2.33.0`: Introduced. * `v2.37.0`: Changed into a public API. #### Values:
Type Description
Save.Type.Auto Browser auto saves.
Save.Type.Base64 Base64 string saves.
Save.Type.Disk Disk saves.
Save.Type.Slot Browser slot saves.
## Browser Saves: General {#save-api-browser} ### `Save.browser.size` → `integer` {#save-api-browser-getter-size} The total number of existing browser saves, both auto and slot. #### History: * `v2.37.0`: Introduced. #### Value: The `integer` count of existing browser saves. #### Examples: ```js console.log(`There are currently ${Save.browser.size} browser saves`); ``` ```js if (Save.browser.size > 0) { /* Browser saves exist. */ } ``` ```js if (Save.browser.size === 0) { /* No browser saves exist. */ } ``` ### `Save.browser.clear()` {#save-api-browser-method-clear} Deletes all existing browser saves, both auto and slot. #### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: *none* #### Throws: *none* #### Examples: ```js Save.browser.clear(); ``` ### `Save.browser.continue()` → `Promise` {#save-api-browser-method-continue} Loads the most recent browser save, either auto or slot.

Note: The default UI includes a Continue button that makes use of this API. Thus, unless you disable or replace the default UI, players already have access to this functionality.

Warning: Saves cannot be loaded during startup and any attempt to do so will cause an error.

#### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: A `Promise` that simply resolves, or rejects with an error if the save could not be loaded. #### Throws: *none* #### Examples: ##### Basic usage Load the most recent browser save, only handling failure. This should be sufficient in the majority of cases. ```js if (Save.browser.size > 0) { Save.browser.continue() .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); } else { /* No browser saves exist. */ } ``` Load the most recent browser save, handling both success and failure. ```js if (Save.browser.size > 0) { Save.browser.continue() .then(() => { /* Success. Do something special. */ }) .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); } else { /* No browser saves exist. */ } ``` ### `Save.browser.isEnabled()` → `boolean` {#save-api-browser-method-isenabled} Determines whether any browser saves are enabled, either auto, slot, or both. #### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: Boolean `true` if any browser saves are enabled, elsewise `false`. #### Throws: *none* #### Examples: ```js if (Save.browser.isEnabled()) { /* Some browser saves are enabled. */ } ``` ## Browser Saves: Auto {#save-api-browser-auto} ### `Save.browser.auto.size` → `integer` {#save-api-browser-auto-getter-size} The total number of existing browser auto saves. #### History: * `v2.37.0`: Introduced. #### Value: The `integer` count of existing browser auto saves. #### Examples: ```js console.log(`There are currently ${Save.browser.auto.size} browser auto saves`); ``` ```js if (Save.browser.auto.size > 0) { /* Browser auto saves exist. */ } ``` ```js if (Save.browser.auto.size === 0) { /* No browser auto saves exist. */ } ``` ### `Save.browser.auto.clear()` {#save-api-browser-auto-method-clear} Deletes all existing auto saves. #### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: *none* #### Throws: *none* #### Examples: ```js Save.browser.auto.clear(); ``` ### `Save.browser.auto.delete(index)` {#save-api-browser-auto-method-delete} Deletes the auto save at the given index. #### History: * `v2.37.0`: Introduced. #### Parameters: * **`index`:** (`integer`) Auto save index (`0`-based). Must be in the range `0`–`Config.saves.maxAutoSaves`. #### Returns: *none* #### Throws: An `Error` instance. #### Examples: Delete the auto save at the given index, handling failure. ```js try { Save.browser.auto.delete(index); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` ### `Save.browser.auto.entries()` → `Array` {#save-api-browser-auto-method-entries} Provides an array of details about all auto saves. #### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: An `Array` of `{ index, info }` generic objects, or an empty `Array` if no auto saves exist. * **`index`:** (`integer`) The auto save's index (`0`-based). * **`info`:** (`object`) The [save's descriptor object](#save-api-objects-descriptor). #### Throws: An `Error` instance. #### Examples: ```js Save.browser.auto.entries().forEach(function (entry) { console.log(`Descriptor of the auto save at index ${entry.index}:`, entry.info); }); ``` ### `Save.browser.auto.get(index)` → `object` {#save-api-browser-auto-method-get} Details the auto save at the given index. #### History: * `v2.37.0`: Introduced. #### Parameters: * **`index`:** (`integer`) Auto save index (`0`-based). Must be in the range `0`–`Config.saves.maxAutoSaves`. #### Returns: The [descriptor object](#save-api-objects-descriptor) for the auto save if it exists, elsewise `null`. #### Throws: An `Error` instance. #### Examples: ```js console.log(`Descriptor of the auto save at index ${index}:`, Save.browser.auto.get(index)); ``` ### `Save.browser.auto.has(index)` → `boolean` {#save-api-browser-auto-method-has} Determines whether the auto save at the given index exists. #### History: * `v2.37.0`: Introduced. #### Parameters: * **`index`:** (`integer`) Auto save index (`0`-based). Must be in the range `0`–`Config.saves.maxAutoSaves`. #### Returns: Boolean `true` if the auto save exists, elsewise `false`. #### Throws: An `Error` instance. #### Examples: ```js if (Save.browser.auto.has(index)) { /* The auto save at the given index exists. */ } ``` ### `Save.browser.auto.isEnabled()` → `boolean` {#save-api-browser-auto-method-isenabled} Determines whether auto saves are enabled. #### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: Boolean `true` if auto saves are anabled, elsewise `false`. #### Throws: *none* #### Examples: ```js if (Save.browser.auto.isEnabled()) { /* Auto saves are enabled. */ } ``` ### `Save.browser.auto.load(index)` → `Promise` {#save-api-browser-auto-method-load} Loads the auto save at the given index.

Warning: Saves cannot be loaded during startup and any attempt to do so will cause an error.

#### History: * `v2.37.0`: Introduced. #### Parameters: * **`index`:** (`integer`) Auto save index (`0`-based). Must be in the range `0`–`Config.saves.maxAutoSaves`. #### Returns: *none* A `Promise` that simply resolves, or rejects with an error if the save could not be loaded. #### Throws: *none* #### Examples: ##### Basic usage Load the auto save at the given index. This should be sufficient in the majority of cases. ```js Save.browser.auto.load(index) .then(() => { Engine.show(); }) .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); ``` ### `Save.browser.auto.save([desc [, metadata]])` {#save-api-browser-auto-method-save} Saves an auto save. If all auto save positions are full, replaces the oldest auto save. #### History: * `v2.37.0`: Introduced. #### Parameters: * **`desc`:** (optional, `string`) The description of the auto save. If omitted or `null`, defaults to the active passage's description. * **`metadata`:** (optional, `any`) The data to be stored in the save object's `metadata` property. *Must* be JSON-serializable. #### Returns: *none* #### Throws: An `Error` instance. #### Examples: ##### Basic usage Save an auto save with the default description and no metadata, handling failure. ```js try { Save.browser.auto.save(); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` Save an auto save with a description and no metadata, handling failure. ```js try { Save.browser.auto.save("In the wilds"); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` Save an auto save with the default description and metadata, handling failure. ```js try { const saveMetadata = { chars : ['Celes', 'Locke', 'Edward'], gold : 2345 }; Save.browser.auto.save(null, saveMetadata); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` Save an auto save with a description and metadata, handling failure. ```js try { const saveMetadata = { chars : ['Celes', 'Locke', 'Edward'], gold : 2345 }; Save.browser.auto.save("In the wilds", saveMetadata); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` ## Browser Saves: Slot {#save-api-browser-slot} ### `Save.browser.slot.size` → `integer` {#save-api-browser-slot-getter-size} The total number of existing browser slot saves. #### History: * `v2.37.0`: Introduced. #### Value: The `integer` count of existing browser slot saves. #### Examples: ```js console.log(`There are currently ${Save.browser.slot.size} browser slot saves`); ``` ```js if (Save.browser.slot.size > 0) { /* Browser slot saves exist. */ } ``` ```js if (Save.browser.slot.size === 0) { /* No browser slot saves exist. */ } ``` ### `Save.browser.slot.clear()` {#save-api-browser-slot-method-clear} Deletes all existing slot saves. #### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: *none* #### Throws: *none* #### Examples: ```js Save.browser.slot.clear(); ``` ### `Save.browser.slot.delete(index)` {#save-api-browser-slot-method-delete} Deletes the slot save at the given index. #### History: * `v2.37.0`: Introduced. #### Parameters: * **`index`:** (`integer`) Slot save index (`0`-based). Must be in the range `0`–`Config.saves.maxSlotSaves`. #### Returns: *none* #### Throws: An `Error` instance. #### Examples: Delete the slot save at the given index, handling failure. ```js try { Save.browser.slot.delete(index); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` ### `Save.browser.slot.entries()` → `Array` {#save-api-browser-slot-method-entries} Provides an array of details about all slot saves. #### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: An `Array` of `{ index, info }` generic objects, or an empty `Array` if no slot saves exist. * **`index`:** (`integer`) The slot save's index (`0`-based). * **`info`:** (`object`) The [save's descriptor object](#save-api-objects-descriptor). #### Throws: An `Error` instance. #### Examples: ```js Save.browser.slot.entries().forEach(function (entry) { console.log(`Descriptor of the slot save at index ${entry.index}:`, entry.info); }); ``` ### `Save.browser.slot.get(index)` → `object` {#save-api-browser-slot-method-get} Details the slot save at the given index. #### History: * `v2.37.0`: Introduced. #### Parameters: * **`index`:** (`integer`) Slot save index (`0`-based). Must be in the range `0`–`Config.saves.maxSlotSaves`. #### Returns: The [descriptor object](#save-api-objects-descriptor) for the slot save if it exists, elsewise `null`. #### Throws: An `Error` instance. #### Examples: ```js console.log(`Descriptor of the slot save at index ${index}:`, Save.browser.slot.get(index)); ``` ### `Save.browser.slot.has(index)` → `boolean` {#save-api-browser-slot-method-has} Determines whether the slot save at the given index exists. #### History: * `v2.37.0`: Introduced. #### Parameters: * **`index`:** (`integer`) Slot save index (`0`-based). Must be in the range `0`–`Config.saves.maxSlotSaves`. #### Returns: Boolean `true` if the slot save exists, elsewise `false`. #### Throws: An `Error` instance. #### Examples: ```js if (Save.browser.slot.has(index)) { /* The slot save at the given index exists. */ } ``` ### `Save.browser.slot.isEnabled()` → `boolean` {#save-api-browser-slot-method-isenabled} Determines whether slot saves are enabled. #### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: Boolean `true` if slot saves are anabled, elsewise `false`. #### Throws: *none* #### Examples: ```js if (Save.browser.slot.isEnabled()) { /* Slot saves are enabled. */ } ``` ### `Save.browser.slot.load(index)` → `Promise` {#save-api-browser-slot-method-load} Loads the slot save at the given index.

Warning: Saves cannot be loaded during startup and any attempt to do so will cause an error.

#### History: * `v2.37.0`: Introduced. #### Parameters: * **`index`:** (`integer`) Slot save index (`0`-based). Must be in the range `0`–`Config.saves.maxSlotSaves`. #### Returns: *none* A `Promise` that simply resolves, or rejects with an error if the save could not be loaded. #### Throws: *none* #### Examples: ##### Basic usage Load the slot save at the given index. This should be sufficient in the majority of cases. ```js Save.browser.slot.load(index) .then(() => { Engine.show(); }) .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); ``` ### `Save.browser.slot.save(index, [desc [, metadata]])` {#save-api-browser-slot-method-save} Saves a slot save to the given index. #### History: * `v2.37.0`: Introduced. #### Parameters: * **`index`:** (`integer`) Slot save index (`0`-based). Must be in the range `0`–`Config.saves.maxSlotSaves`. * **`desc`:** (optional, `string`) The description of the slot save. If omitted or `null`, defaults to the active passage's description. * **`metadata`:** (optional, `any`) The data to be stored in the save object's `metadata` property. *Must* be JSON-serializable. #### Returns: *none* #### Throws: An `Error` instance. #### Examples: ##### Basic usage Save to slot save index `0` with the default description and no metadata, handling failure. ```js try { Save.browser.slot.save(0); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` Save to slot save index `0` with a description and no metadata, handling failure. ```js try { Save.browser.slot.save(0, "In the wilds"); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` Save to slot save index `0` with the default description and metadata, handling failure. ```js try { const saveMetadata = { chars : ['Celes', 'Locke', 'Edward'], gold : 2345 }; Save.browser.slot.save(0, null, saveMetadata); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` Save to slot save index `0` with a description and metadata, handling failure. ```js try { const saveMetadata = { chars : ['Celes', 'Locke', 'Edward'], gold : 2345 }; Save.browser.slot.save(0, "In the wilds", saveMetadata); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` ## Disk Saves {#save-api-disk} ### `Save.disk.export(filename)` {#save-api-disk-method-export} Exports all existing browser saves as a bundle to disk, which may be restored via [`Save.disk.import()`](#save-api-disk-method-import). #### History: * `v2.37.0`: Introduced. #### Parameters: * **`filename`:** (`string`) The base filename of the browser save export, which gets slugified to remove most symbols. Appended to this is a datestamp (format: `YYYMMDD-hhmmss`) and the file extension `.savesbundle`—e.g., `"The Scooby Chronicles"` would result in the full filename: `the-scooby-chronicles-{datestamp}.savesbundle`. #### Returns: *none* #### Throws: An `Error` instance. #### Examples: Export all saves as a bundle with a base filename, handling failure. ```js try { Save.disk.export('The 6th Fantasy'); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` ### `Save.disk.import(event)` → `Promise` {#save-api-disk-method-import} Imports a saves bundle from disk, created via [`Save.disk.export()`](#save-api-disk-method-export).

Note: This method must be used as, or be called by, the change event handler of an <input type="file"> element.

Warning: All existing browser saves will be deleted as part of restoring the exported save bundle.

#### History: * `v2.37.0`: Introduced. #### Parameters: * **`event`:** (`Event`) The event object that was passed to the `change` event handler of the associated `` element. #### Returns: A `Promise` that simply resolves, or rejects with an error if the browser saves bundle could not be imported. #### Throws: *none* #### Examples: ##### Basic usage Import the saves bundle from disk, only handling failure. This should be sufficient in the majority of cases. ```js jQuery(document.createElement('input')) .prop({ id : 'saves-import-file', name : 'saves-import-file', type : 'file' }) .on('change', ev => { // You must provide the event to Save.disk.import() Save.disk.import(ev) .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); }); ``` Import the saves bundle from disk, handling both success and failure. ```js jQuery(document.createElement('input')) .prop({ id : 'saves-import-file', name : 'saves-import-file', type : 'file' }) .on('change', function (ev) { // You must provide the event to Save.browser.import() Save.disk.import(ev) .then(() => { /* Success. Do something special. */ }) .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); }); ``` ### `Save.disk.load(event)` → `Promise` {#save-api-disk-method-load} Loads the given save from disk, created via [`Save.disk.save()`](#save-api-disk-method-save).

Note: This method must be used as, or be called by, the change event handler of an <input type="file"> element.

Warning: Saves cannot be loaded during startup and any attempt to do so will cause an error.

#### History: * `v2.37.0`: Introduced. #### Parameters: * **`event`:** (`Event`) The event object that was passed to the `change` event handler of the associated `` element. #### Returns: A `Promise` that resolves with the save's metadata (`any`), or rejects with an error if the save could not be loaded. #### Throws: *none* #### Examples: ##### Basic usage Load the disk save. This should be sufficient in the majority of cases. ```js jQuery(document.createElement('input')) .prop({ id : 'saves-disk-load-file', name : 'saves-disk-load-file', type : 'file' }) .on('change', ev => { // You must provide the event to Save.disk.load() Save.disk.load(ev) .then(metadata => { Engine.show(); }) .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); }); ``` ##### As a self-contained button using macros ``` <> ``` ### `Save.disk.save(filename [, metadata])` {#save-api-disk-method-save} Saves the current story state to disk, which may be restored via [`Save.disk.load()`](#save-api-disk-method-load). #### History: * `v2.37.0`: Introduced. #### Parameters: * **`filename`:** (`string`) The base filename of the disk save, which gets slugified to remove most symbols. Appended to this is a datestamp (format: `YYYMMDD-hhmmss`) and the file extension `.save`—e.g., `"The Scooby Chronicles"` would result in the full filename: `the-scooby-chronicles-{datestamp}.save`. * **`metadata`:** (optional, `any`) The data to be stored in the save object's `metadata` property. *Must* be JSON-serializable. #### Returns: *none* #### Throws: An `Error` instance. #### Examples: Save with a base filename and no metadata, handling failure. ```js try { Save.disk.save("The 6th Fantasy"); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` Save with a base filename and metadata, handling failure. ```js try { const saveMetadata = { chars : ['Celes', 'Locke', 'Edward'], gold : 2345 }; Save.disk.save("The 6th Fantasy", saveMetadata); } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` ## Base64 Saves {#save-api-base64} ### `Save.base64.export()` → `string` {#save-api-base64-method-export} Exports all existing browser saves as a bundle to a Base64 string, which may be restored via [`Save.base64.import()`](#save-api-base64-method-import). #### History: * `v2.37.0`: Introduced. #### Parameters: *none* #### Returns: *none* #### Throws: An `Error` instance. #### Examples: Export all saves as a bundle, handling failure. ```js try { const base64Save = Save.base64.export(); /* Do something with the saves bundle. */ } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` ### `Save.base64.import(bundle)` → `Promise` {#save-api-base64-method-import} Imports the given Base64 saves bundle string, created via [`Save.base64.export()`](#save-api-base64-method-export).

Warning: All existing browser saves will be deleted as part of restoring the exported save bundle.

#### History: * `v2.37.0`: Introduced. #### Parameters: * **`bundle`:** (`string`) The Base64 saves bundle string. #### Returns: A `Promise` that simply resolves, or rejects with an error if the browser saves bundle could not be imported. #### Throws: *none* #### Examples: ##### Basic usage Import the saves bundle, only handling failure. This should be sufficient in the majority of cases. ```js Save.base64.import(base64Bundle) .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); ``` Import the saves bundle, handling both success and failure. ```js Save.base64.import(base64Bundle) .then(() => { /* Success. Do something special. */ }) .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); ``` ### `Save.base64.load(save)` → `Promise` {#save-api-base64-method-load} Loads the given Base64 save string, created via [`Save.base64.save()`](#save-api-base64-method-save).

Warning: Saves cannot be loaded during startup and any attempt to do so will cause an error.

#### History: * `v2.37.0`: Introduced. #### Parameters: * **`save`:** (`string`) The Base64 save string. #### Returns: A `Promise` that resolves with the save's metadata (`any`), or rejects with an error if the save could not be loaded. #### Throws: *none* #### Examples: ##### Basic usage Load the save string. This should be sufficient in the majority of cases. ```js Save.base64.load(base64Save) .then(metadata => { Engine.show(); }) .catch(error => { /* Failure. Handle the error. */ console.error(error); UI.alert(error); }); ``` ### `Save.base64.save([metadata])` → `string` {#save-api-base64-method-save} Saves the current story state as a Base64 string. #### History: * `v2.37.0`: Introduced. #### Parameters: * **`metadata`:** (optional, `any`) The data to be stored in the save object's `metadata` property. *Must* be JSON-serializable. #### Returns: A Base64 save `string`. #### Throws: An `Error` instance. #### Examples: ##### Basic usage Save without metadata, handling failure. ```js try { const base64Save = Save.base64.save(); /* Do something with the save. */ } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` Save with metadata, handling failure. ```js try { const saveMetadata = { chars : ['Celes', 'Locke', 'Edward'], gold : 2345 }; const base64Save = Save.base64.save(saveMetadata); /* Do something with the save. */ } catch (error) { /* Failure. Handle the error. */ console.error(error); UI.alert(error); } ``` ## Save Events {#save-api-events} ### `Save.onLoad.size` → `integer` {#save-api-onload-getter-size} The total number of currently registered on-load handlers. #### History: * `v2.36.0`: Introduced. #### Value: The `integer` count of currently registered on-load handlers. #### Examples: ```js console.log('There are %d onLoad handlers registered.', Save.onLoad.size); ``` ### `Save.onLoad.add(handler)` {#save-api-onload-method-add} Performs any required processing before the save data is loaded—e.g., upgrading out-of-date save data. The handler is passed one parameter, the save object to be processed. If it encounters an unrecoverable problem during its processing, it may throw an exception containing an error message; the message will be displayed to the player and loading of the save will be terminated. #### History: * `v2.36.0`: Introduced. #### Parameters: * **`handler`:** (*function*) The handler function to be executed upon the loading of a save. #### Returns: *none* #### Throws: An `Error` instance. #### Handler parameters: * **`save`:** (`object`) The [save object](#save-api-save-objects) to be processed. #### Examples: ##### Basic usage ```js Save.onLoad.add(function (save) { /* code to process the save object before it's loaded */ }); ``` ##### Using save objects' `type` property and the `Save.Type` pseudo-enumeration ```js Save.onLoad.add(function (save) { switch (save.type) { case Save.Type.Auto: { /* code to process an auto save object before it's loaded */ break; } case Save.Type.Base64: { /* code to process a base64 save object before it's loaded */ break; } case Save.Type.Disk: { /* code to process a disk save object before it's loaded */ break; } case Save.Type.Slot: { /* code to process a slot save object before it's loaded */ break; } } }); ``` ### `Save.onLoad.clear()` {#save-api-onload-method-clear} Deletes all currently registered on-load handlers. #### History: * `v2.36.0`: Introduced. #### Parameters: *none* #### Returns: *none* #### Throws: *none* #### Examples: ```js Save.onLoad.clear(); ``` ### `Save.onLoad.delete(handler)` → `boolean` {#save-api-onload-method-delete} Deletes the specified on-load handler. #### History: * `v2.36.0`: Introduced. #### Parameters: * **`handler`:** (*function*) The handler function to be deleted. #### Returns: Boolean `true` if the handler existed, elsewise `false`. #### Throws: *none* #### Examples: ```js // Given: // let myOnLoadHandler = function (save) { // /* code to process the save object before it's loaded */ // }; // Save.onLoad.add(myOnLoadHandler); Save.onLoad.delete(myOnLoadHandler); ``` ### `Save.onSave.size` → `integer` {#save-api-onsave-getter-size} The total number of currently registered on-save handlers. #### History: * `v2.36.0`: Introduced. #### Value: The `integer` count of currently registered on-save handlers. #### Examples: ```js console.log('There are %d onSave handlers registered.', Save.onSave.size); ``` ### `Save.onSave.add(handler)` {#save-api-onsave-method-add} Performs any required processing before the save data is saved. The handler is passed one parameter, the save object to be processed. #### History: * `v2.36.0`: Introduced. * `v2.37.0`: Deprecated handlers' `details` parameter. #### Parameters: * **`handler`:** (*function*) The handler function to be executed upon the saving of a save. #### Returns: *none* #### Throws: An `Error` instance. #### Handler parameters: * **`save`:** (`object`) The [save object](#save-api-save-objects) to be processed. #### Examples: ##### Basic usage ```js Save.onSave.add(function (save) { /* code to process the save object before it's saved */ }); ``` ##### Using save objects' `type` property and the `Save.Type` pseudo-enumeration ```js Save.onSave.add(function (save) { switch (save.type) { case Save.Type.Auto: { /* code to process an auto save object before it's saved */ break; } case Save.Type.Base64: { /* code to process a base64 save object before it's saved */ break; } case Save.Type.Disk: { /* code to process a disk save object before it's saved */ break; } case Save.Type.Slot: { /* code to process a slot save object before it's saved */ break; } } }); ``` ### `Save.onSave.clear()` {#save-api-onsave-method-clear} Deletes all currently registered on-save handlers. #### History: * `v2.36.0`: Introduced. #### Parameters: *none* #### Returns: *none* #### Throws: *none* #### Examples: ```js Save.onSave.clear(); ``` ### `Save.onSave.delete(handler)` → `boolean` {#save-api-onsave-method-delete} Deletes the specified on-save handler. #### History: * `v2.36.0`: Introduced. #### Parameters: * **`handler`:** (*function*) The handler function to be deleted. #### Returns: Boolean `true` if the handler existed, elsewise `false`. #### Throws: *none* #### Examples: ```js // Given: // let myOnSaveHandler = function (save) { // /* code to process the save object before it's saved */ // }; // Save.onSave.add(myOnSaveHandler); Save.onSave.delete(myOnSaveHandler); ``` ## Deprecated APIs {#save-api-deprecated} ### `Save.clear()` {#save-api-method-clear}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.clear() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.clear()` method. ### `Save.get()` {#save-api-method-get}

Deprecated: This method has been deprecated and should no longer be used.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated. ### `Save.ok()` → `boolean` {#save-api-method-ok}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.isEnabled() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.isEnabled()` method. ### `Save.autosave.delete()` {#save-api-method-autosave-delete}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.auto.delete() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.auto.delete()` method. ### `Save.autosave.get()` → `object` {#save-api-method-autosave-get}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.auto.get() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.auto.get()` method. ### `Save.autosave.has()` → `boolean` {#save-api-method-autosave-has}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.auto.has() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.auto.has()` method. ### `Save.autosave.load()` {#save-api-method-autosave-load}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.auto.load() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.auto.load()` method. ### `Save.autosave.ok()` → `boolean` {#save-api-method-autosave-ok}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.auto.isEnabled() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.auto.isEnabled()` method. ### `Save.autosave.save([title [, metadata]])` {#save-api-method-autosave-save}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.auto.save() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.auto.save()` method. ### `Save.slots.length` → `integer` {#save-api-getter-slots-length}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.slot.size property for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.slot.size` property. ### `Save.slots.count()` → `integer` {#save-api-method-slots-count}

Deprecated: This method has been deprecated and should no longer be used.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated. ### `Save.slots.delete(slot)` {#save-api-method-slots-delete}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.slot.delete() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.slot.delete()` method. ### `Save.slots.get(slot)` → `object` {#save-api-method-slots-get}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.slot.get() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.slot.get()` method. ### `Save.slots.has(slot)` → `boolean` {#save-api-method-slots-has}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.slot.has() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.slot.has()` method. ### `Save.slots.isEmpty()` → `boolean` {#save-api-method-slots-isempty}

Deprecated: This method has been deprecated and should no longer be used.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated. ### `Save.slots.load(slot)` {#save-api-method-slots-load}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.slot.load() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.slot.load()` method. ### `Save.slots.ok()` → `boolean` {#save-api-method-slots-ok}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.slot.isEnabled() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.slot.isEnabled()` method. ### `Save.slots.save(slot [, title [, metadata]])` {#save-api-method-slots-save}

Deprecated: This method has been deprecated and should no longer be used. See the Save.browser.slot.save() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.browser.slot.save()` method. ### `Save.import(event)` {#save-api-method-import}

Deprecated: This method has been deprecated and should no longer be used. See the Save.disk.load() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.disk.load()` method. ### `Save.export([filename [, metadata]])` {#save-api-method-export}

Deprecated: This method has been deprecated and should no longer be used. See the Save.disk.save() method for its replacement.

#### History: * `v2.0.0`: Introduced. * `v2.8.0`: Added `metadata` parameter. * `v2.37.0`: Deprecated in favor of the `Save.disk.save()` method. ### `Save.deserialize(saveStr)` → `any` | `null` {#save-api-method-deserialize}

Deprecated: This method has been deprecated and should no longer be used. See the Save.base64.load() method for its replacement.

#### History: * `v2.21.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.base64.load()` method. ### `Save.serialize([metadata])` → `string` | `null` {#save-api-method-serialize}

Deprecated: This method has been deprecated and should no longer be used. See the Save.base64.save() method for its replacement.

#### History: * `v2.21.0`: Introduced. * `v2.37.0`: Deprecated in favor of the `Save.base64.save()` method.