The Savegame API enables developers to store and retrieve player game data, which allows players to save their progress and resume game play at a later time.
The save data are stored on the server and therefore synced across all of the user's devices.
This API currently only supports recording progress for authenticated users. This feature will soon support recording progress for unauthenticated users as well.
The save record contains the following information:
A technical representation of the save data would look like this:
interface SaveSlot {
name: string;
save_data: any;
created_at: string; // ISO 8601 date format
updated_at: string; // ISO 8601 date format
}
All features are accessible via the heyVR.savegame object. This object offers the following methods that you can use:
The following method allows developers to retrieve all game data that is currently saved for the current user.
heyVR.saveGame.all() : Promise<{ [slot: string]: SaveSlot }>
Please note that the returned
slotis a numeric string and not an integer due to JSON's limitations.
An example output of the response would be similar to the following:
{
"1" : {
"name": "First Slot",
"saveData": {"your":"saved data"},
"created_at": "2023-03-09T03:43:26.000000Z",
"updated_at": "2023-03-09T03:44:26.000000Z"
},
"2" : {
"name": "Second Slot",
"saveData": {"another":"game saved data"},
"created_at": "2023-03-10T11:15:20.000000Z",
"updated_at": "2023-03-10T12:03:11.000000Z"
},
}
The following method allows developers to wipe all game data that is currently saved for the current user.
Attention: Wiping all user saves is irreversible. Handle with care!
heyVR.saveGame.wipe() : Promise<boolean>
Promise<boolean>)The following method allows developers to load game data from a specific save slot.
heyVR.saveGame.load( slot: number ) : Promise<SaveSlot>
slot: The index of the savegame the user wants to load (1 through 5). Defaults to 1 if left empty.slot must exist.Promise<SaveSlot>). If the save slot doesn't exist, the promise will be rejected.The following method allows developers to write game data to a specific save slot.
heyVR.saveGame.write(
saveData: any,
overwrite: boolean | null,
slot: number | null,
name: string | null
) : Promise<boolean>
saveData: Required. the data you want to store. Required. Must be valid to pass to JSON.stringify().overwrite: Whether to overwrite the slot if it exists. Defaults to false if not provided.slot: The index of the savegame to write to. Defaults to 1 if not provided.name:The name of the save slot. Default is the slot number prefixed with the word Slot, for example Slot 2slot must be empty or overwrite set to truePromise that resolves to true if the save was successful, or rejects if there was an error.The following method allows developers to remove game data from a specific save slot.
heyVR.saveGame.remove( slot:number | null ) : Promise<SaveSlot>
slot: The index of the savegame the user wants to delete. Defaults to 1 if not provided.slot must exist.Promise that's resolved to true if the save data is deleted, or rejected if an error occurred.