Monogatari provides a flexible save system that allows players to save and load their progress.
Save Settings
| Setting | Type | Default | Description |
|---|---|---|---|
Slots |
number |
10 |
Number of save slots available |
SaveLabel |
string |
'Save' |
Prefix for save slot storage keys |
AutoSaveLabel |
string |
'AutoSave' |
Prefix for auto-save slot storage keys |
AutoSave |
number |
0 |
Auto-save interval in minutes (0 = off) |
Number of Save Slots
Control how many save slots are available:
monogatari.settings({
'Slots': 10 // 10 save slots available
});Increase for games where players may want more save points:
monogatari.settings({
'Slots': 20 // 20 save slots
});Save Slot Prefixes
Multiple Games on Same Domain
If you host multiple games on the same domain, they will share save data by default. To prevent this, use unique prefixes:
// Game 1
monogatari.settings({
'Name': 'MyFirstGame',
'SaveLabel': 'Game1_Save',
'AutoSaveLabel': 'Game1_Auto'
});
// Game 2
monogatari.settings({
'Name': 'MySecondGame',
'SaveLabel': 'Game2_Save',
'AutoSaveLabel': 'Game2_Auto'
});Auto-Save
Enabling Auto-Save
Set the AutoSave setting to the interval (in minutes) between automatic saves:
monogatari.settings({
'AutoSave': 5 // Auto-save every 5 minutes
});Disabling Auto-Save
Set to 0 to disable auto-saving (default):
monogatari.settings({
'AutoSave': 0 // Auto-save disabled
});Auto-Save Behavior
When auto-save is enabled:
- The game saves automatically at the specified interval
- Auto-saves are stored separately from manual saves
- The load screen shows both manual saves and auto-saves
- Auto-saves are labeled with the
AutoSaveLabelprefix
Storage Configuration
Control how and where game data is stored:
monogatari.settings({
'Storage': {
'Adapter': 'LocalStorage',
'Store': 'GameData',
'Endpoint': ''
}
});Storage Adapters
| Adapter | Description | Use Case |
|---|---|---|
LocalStorage |
Browser’s localStorage (default) | Most web games |
SessionStorage |
Cleared when browser closes | Temporary/demo games |
IndexedDB |
IndexedDB API | Large amounts of data |
RemoteStorage |
REST API endpoint | Cloud saves |
Remote Storage Example
For cloud saves:
monogatari.settings({
'Storage': {
'Adapter': 'RemoteStorage',
'Store': 'GameData',
'Endpoint': 'https://api.mygame.com/saves'
}
});Save Data Contents
When a game is saved, Monogatari stores:
- Current label and step position
- All state variables
- All storage variables
- History for all actions
- Player preferences
- Timestamp and slot name
Programmatic Save/Load
Saving Programmatically
// Save to a specific slot
monogatari.saveTo('Save_1', 'My Save Name');
// Auto-save
monogatari.autoSave();Loading Programmatically
// Load from a slot
monogatari.loadFrom('Save_1');Checking for Saves
// Get all save slots
const saves = monogatari.saves();
// Check if a slot exists
if (saves['Save_1']) {
console.log('Save exists');
}Save Slot UI
The save and load screens are provided by built-in components. You can customize them using the template method:
// Customize save screen
monogatari.component('save-screen').template(() => {
return `
<!-- Your custom template -->
`;
});Related
- Game Configuration - All game settings
- Asset Preloading - Loading screen configuration
- Player Preferences - Player settings