UserPersistentDataService class

Allows access to module data per user for storing or retrieving custom data persistently on the server. The data does not expire and is free form.

Signature:

export declare class UserPersistentDataService extends ExternalObject 

Extends: ExternalObject

Remarks

Use Runtime.getUserPersistentDataService() to get an instance of this class.

Methods

MethodModifiersDescription
getPerOoohDataAsync()Loads this user's saved data for the current Oooh as saved in any level of the current Oooh
getSettingsDataAsync()Loads this user's global saved data for the module as saved in any run of the module across any version.
setPerOoohDataAsync(data)Saves data for this user associated with the current Oooh, can be loaded from either a replay of this level of this Oooh, or during a play of another level of this Oooh.
setSettingsDataAsync(data)Saves data for the user associated with every run of this module.

UserPersistentDataService.getPerOoohDataAsync() method

Loads this user's saved data for the current Oooh as saved in any level of the current Oooh

Signature:

getPerOoohDataAsync(): unknown;

Returns:

unknown

The last object saved with UserPersistentDataService.setPerOoohDataAsync() or null if there was no previous save for this user in this Oooh

Remarks

For example this is the data stored for Jack after joining a game created/hosted by Jill.

Example

// Don't do this, you should always get the service from the Instance instead
// const service = new o3h.UserPersistentDataService();
const service = await o3h.Instance.getUserPersistentDataService(); // Do this
await service.getPerOoohDataAsync();

UserPersistentDataService.getSettingsDataAsync() method

Loads this user's global saved data for the module as saved in any run of the module across any version.

Signature:

getSettingsDataAsync(): unknown;

Returns:

unknown

The last object saved with UserPersistentDataService.setSettingsDataAsync() or null if there was no previous save for this user

Remarks

For example, this could be the deck of cards the user has for this particular title.

This is global data for the user bound to your module.

*

Example

// Don't do this, you should always get the service from the Instance instead
// const service = new o3h.UserPersistentDataService();
const service = await o3h.Instance.getUserPersistentDataService(); // Do this
await service.getSettingsDataAsync();

UserPersistentDataService.setPerOoohDataAsync() method

Saves data for this user associated with the current Oooh, can be loaded from either a replay of this level of this Oooh, or during a play of another level of this Oooh.

Signature:

setPerOoohDataAsync(data: unknown): Promise<boolean>;

Parameters

ParameterTypeDescription
dataunknownThe data to store. Currently limited to 400KB.

Returns:

Promise<boolean>

true if successful, false if it fails.

Remarks

Existing data will be overwritten with the new data.

*

Example

// Don't do this, you should always get the service from the Instance instead
// const service = new o3h.UserPersistentDataService();
const service = await o3h.Instance.getUserPersistentDataService(); // Do this
await service.setPerOoohDataAsync({ value: 1 });

// ...

// This data will persist across joins of this Oooh only
const entry = await service.getPerOoohDataAsync();
console.log(entry.value); // 1

UserPersistentDataService.setSettingsDataAsync() method

Saves data for the user associated with every run of this module.

Signature:

setSettingsDataAsync(data: unknown): Promise<boolean>;

Parameters

ParameterTypeDescription
dataunknownThe data to store. Currently limited to 400KB.

Returns:

Promise<boolean>

True if successful, false if it fails.

Remarks

Existing data will be overwritten with the new data.

Data saved in this manor must be both forwards and backwards compatible with the data saved in all deliveries of your module. As a user playing an old Oooh will play an old version of your module.

Example of a bad data change and a suggestion for how to handle this better, referencing the Examples below:

  1. If a user saves data with Version 2 and then plays Version 1 they'll fail to parse the data as 'value' is no longer a string value.
  2. If a user saves data with Version 1 and then plays Version 2 they'll fail to parse the data as 'value' is a string and not an object as expected
  3. Version 3 would be a better choice for a data change as the 'value' is still readable in both versions.
Note: that if a user saves with Version 1 the extended data will be lost in Version 3 still.

*

Example 1

// Don't do this, you should always get the service from the Instance instead
// const service = new o3h.UserPersistentDataService();
const service = await o3h.Instance.getUserPersistentDataService(); // Do this
await service.setSettingsDataAsync({ value: 1 });

// ...

// This data will persist across all instances of the module
const entry = await service.getSettingsDataAsync();
console.log(entry.value); // 1

Example 2

Version 1
{
    value: "value"
}

Example 3

Version 2
{
    value: {
        part1: "value",
        part2: "value2"
    }
}

Example 4

Version 3
{
    value: "value",
    valueExtended: {
        "part2" : "value2"
    }
}