GeneralDataStore
Lens Studio v2.0.0+
Inherits from ScriptObject
Description
Class for storing and retrieving data based on keys. Used by PersistentStorageSystem. For more information, see the Persistent Storage guide.
Methods
clear()
: void
Clears all data stored in the General Data Store.
getBool(String key)
: Boolean
Returns a boolean value stored under the given key, or false if none exists.
getBoolArray(String key)
: Boolean[]
Returns a boolean array being stored under the given key, or an empty array if none exists.
getDouble(String key)
: Number
Returns a double precision floating point number stored under the given key, or 0 if none exists.
getFloat(String key)
: Number
Returns a floating point value stored under the given key, or 0 if none exists.
getFloatArray(String key)
: Number[]
Returns a floating point array being stored under the given key, or an empty array if none exists.
getInt(String key)
: Number
Returns an integer number stored under the given key, or 0 if none exists.
getIntArray(String key)
: Number[]
Returns an integer array being stored under the given key, or an empty array if none exists.
getMat2(String key)
: mat2
Returns a mat2 value stored under the given key, or a default mat2 if none exists.
getMat2Array(String key)
: mat2
[]
Returns a mat2 array being stored under the given key, or an empty array if none exists.
getMat3(String key)
: mat3
Stores a mat3 value under the given key.
getMat3Array(String key)
: mat3
[]
Returns a mat3 array being stored under the given key, or an empty array if none exists.
getMat4(String key)
: mat4
Returns a mat4 value stored under the given key, or a default mat4 if none exists.
getMat4Array(String key)
: mat4
[]
Returns a mat4 array being stored under the given key, or an empty array if none exists.
getMaxSizeInBytes()
: Number
Returns the maximum total size allowed, in bytes, of all data stored in this General Data Store.
getQuat(String key)
: quat
Returns a quat value stored under the given key, or a default quat if none exists.
getQuatArray(String key)
: quat
[]
Returns a quat array being stored under the given key, or an empty array if none exists.
getSizeInBytes()
: Number
If onStoreFull
has been set, this method returns the current total size, in bytes, of all data stored in this General Data Store. Otherwise, 0
is returned.
getString(String key)
: String
Returns a string value stored under the given key, or empty string if none exists.
getStringArray(String key)
: String[]
Returns a string array being stored under the given key, or an empty array if none exists.
getVec2(String key)
: vec2
Returns a vec2 value stored under the given key, or a default vec2 if none exists.
getVec2Array(String key)
: vec2
[]
Returns a vec2 array being stored under the given key, or an empty array if none exists.
getVec3(String key)
: vec3
Returns a vec3 value stored under the given key, or a default vec3 if none exists.
getVec3Array(String key)
: vec3
[]
Returns a vec3 array being stored under the given key, or an empty array if none exists.
getVec4(String key)
: vec4
Returns a vec4 value stored under the given key, or a default vec4 if none exists.
getVec4Array(String key)
: vec4
[]
Returns a vec4 array being stored under the given key, or an empty array if none exists.
has(String key)
: Boolean
Returns true if a value is being stored under the given key.
putBool(String key, Boolean value)
: void
Stores a boolean value under the given key.
putBoolArray(String key, Boolean[] value)
: void
Stores a boolean array under the given key.
putDouble(String key, Number value)
: void
Stores a double precision floating point number under the given key.
putFloat(String key, Number value)
: void
Stores a floating point value under the given key.
putFloatArray(String key, Number[] value)
: void
Stores a floating point array under the given key.
putInt(String key, Number value)
: void
Stores an integer number value under the given key.
putIntArray(String key, Number[] value)
: void
Stores an integer array under the given key.
putMat2(String key, mat2 value)
: void
Stores a mat2 value under the given key.
putMat2Array(String key, mat2[] value)
: void
Stores a mat2 array under the given key.
putMat3(String key, mat3 value)
: void
Stores a mat3 value under the given key.
putMat3Array(String key, mat3[] value)
: void
Stores a mat3 array under the given key.
putMat4(String key, mat4 value)
: void
Stores a mat4 value under the given key.
putMat4Array(String key, mat4[] value)
: void
Stores a mat4 array under the given key.
putQuat(String key, quat value)
: void
Stores a quat value under the given key.
putQuatArray(String key, quat[] value)
: void
Stores a quat array under the given key.
putString(String key, String value)
: void
Stores a string value under the given key.
putStringArray(String key, String[] value)
: void
Stores a string array under the given key.
putVec2(String key, vec2 value)
: void
Stores a vec2 value under the given key.
putVec2Array(String key, vec2[] value)
: void
Stores a vec2 array under the given key.
putVec3(String key, vec3 value)
: void
Stores a vec3 value under the given key.
putVec3Array(String key, vec3[] value)
: void
Stores a vec3 array under the given key.
putVec4(String key, vec4 value)
: void
Stores a vec4 value under the given key.
putVec4Array(String key, vec4[] value)
: void
Stores a vec4 array under the given key.
remove(String key)
: void
Removes the value being stored under the given key. If no value exists under the key, nothing will happen.
Properties
onStoreFull
: function
Callback function that gets called when the allowed storage limit has been passed. The store won’t be saved if it is full, so if this is called make sure to remove data until back under the limit.
Inherited Methods
getTypeName()
: String
Returns the name of this object’s type.
isOfType(String type)
: Boolean
Returns true if the object matches or derives from the passed in type.
Examples
// 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 for this key
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);
// Check Launch Params for a certain string value
var stringParamName = "testString";
if (global.launchParams && global.launchParams.has(stringParamName)) {
var myString = global.launchParams.getString(stringParamName);
}
Still Looking for help?
Visit Support