📰Getting Started | ⭐**Updates |** 📝 Guides | 🔢 API | ❓FAQ
Web Editor Basics
HoloLens
Mobile
Meta Quest
Chapter Series Documentation
Assets
Scripting
Enklu Embedded
API Reference
Release Notes
FAQ
Contact
The Storage API allows you cache persistent data across various scopes, including device, experience, and in the cloud. The interface behaves similarly to the current web standards.
Any data saved in the web editor will be removed when the session ends.
const storage = require('storage-preview');
Here are the currently available scopes:
storage.local // per-experience
storage.device // per-device
storage.player // per-player cloud storage
storage.players // access all players
For each scope, data can be saved and retrieved using the same functions setItem
and getItem
. Complex objects can be used with JSON.stringify
and JSON.parse
. Data can be removed from storage via removeItem
and clear
. Clear will only remove data for the currently loaded experience.
var data = {
points: 26,
currency: 42
}
// store data
storage.local.setItem('session', JSON.stringify(data));
// retrieve data.
var data = JSON.parse(storage.local.getItem('session'));
if (data) {
log.info('Previous data found.');
log.info(' Points: ' + data.points);
log.info(' Currency: ' + data.currency);
}
Information about keys can be accessed via length
and key
. This can be useful to iterate over storage data.
const numKeys = storage.local.length;
for (var i = 0; i < numKeys; i++) {
const key = storage.local.key(i);
const data = JSON.parse(storage.local.getItem(key));
log.info(key + ': ' + data);
}
local <Storage>
The storage object for the current device.
player <Storage>
storage.player
supports, loading, modifying, and persisting data to the cloud for the current player. The following APIs are provided in addition to the Storage
API
storage.player.loadPlayer(userid)
Makes available the cloud data for the given user in storage.player
. Returns an IAsyncJsResponse
that has then()
and fail()
methods that are called back accordingly when the operation is completed
storage.player.persistPlayer()
Persists the current player to the cloud. Returns an IAsyncJsResponse
that has then()
and fail()
methods that are called back accordingly when the operation is completed.
players
storage.players
supports reading a different players data from the cloud. This data is not cached on devices and all APIs return an IAsyncJsResponse
(the standard Storage
API is not supported for this reason)
storage.players.getPlayerItem(userid, key)
Returns the string value associated with the key for the given player in an IAsyncJsResponse
storage.players.getPlayerData(userid)
Returns all of the data associated with the given user as a JSON dictionary
Storage
Class Propertieslength <int>
The number of entries stored.
Storage
Class Methodskey(index)
index <int>
The index to retrieve.Fetches a storage key based on an index.
getItem(key)
key <string>
The key to retrieve data for.Gets a value based on a key and returns null
if not found.
setItem(key, value)
key <string>
The key to set a value for.value <string>
The new or updated serialized value.true
if successfulSets a value for a given key.
removeItem(key)
key <string>
The key to remove.true
if successfulRemoves an entry from storage for a given key.
clear()
true
if successfulClears all data from storage.
Next: System
Sidebar Table of Contents
Copyright © 2021 Enklu, Inc.