Skip to main content

PersistentStorageSystem

Class

Allows data to be stored and retrieved between Lens sessions.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Allows data to be stored and retrieved between Lens sessions. In other words, data can be saved on device and loaded back in the next time the Lens is opened. Can be accessed with global.persistentStorageSystem.

See the Persistent Storage guide for more information.

Index

Example

// Get the data store from PersistentStorageSystem
var store = global.persistentStorageSystem.store;

// Load score from previous Lens session. Defaults to 0 if data isn't found
var score = store.getFloat("totalScore");
print("loaded score: " + score);

function increaseScore() {
// Increase score, then write it to the data store
score += 1;
store.putFloat("totalScore", score);
print("new score: " + score);
}

// Increase score on tap event
script.createEvent("TapEvent").bind(increaseScore);

Extends

Properties

sessionStore

sessionStore: DataStoreWithScene

The DataStoreWithScene object used to store and retrieve session-scoped data. Data persists across multiple Snaps within the same Lens session (until a different Lens is opened). Unlike PersistentStorageSystem#store, this store supports saving procedural assets such as MeshBuilder meshes and ProceduralTextureProvider textures.

Since

Lens Scripting Version 354

Default Value

null

store

store: GeneralDataStore

The GeneralDataStore object used to store and retrieve data.

Default Value

null

Methods

getTypeName()

static getTypeName(): TypeName<PersistentStorageSystem>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<PersistentStorageSystem>

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame