Settings

Description

The Settings API provides a facility to store and retrieve values that persist between Interface runs.

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts

Methods

Name Return Value Summary
getValue string | number | boolean | object Retrieves the value from a named setting.
setValue None Stores a value in a named setting. If the setting already exists, its value is overwritten. If the value is null or undefined, the setting is deleted.

Method Details

(static) getValue( key, defaultValueopt ) → {string|number|boolean|object}
Returns: The value stored in the named setting if it exists, otherwise the defaultValue.

Retrieves the value from a named setting.

Parameters

Name Type Attributes Default Value Description
key string The name of the setting.
defaultValue string | number | boolean | object <optional>
"" The value to return if the setting doesn't exist.
Example

Retrieve non-existent setting values.

var value1 = Settings.getValue("Script Example/Nonexistent Key");
print("Value: " + (typeof value1) + " " + JSON.stringify(value1));  // string ""

var value2 = Settings.getValue("Script Example/Nonexistent Key", true);
print("Value: " + (typeof value2) + " " + JSON.stringify(value2));  // boolean true
(static) setValue( key, value )

Stores a value in a named setting. If the setting already exists, its value is overwritten. If the value is null or undefined, the setting is deleted.

Parameters

Name Type Description
key string The name of the setting. Be sure to use a unique name if creating a new setting.
value string | number | boolean | object | undefined The value to store in the setting. If null or undefined is specified, the setting is deleted.
Example

Store and retrieve an object value.

Settings.setValue("Script Example/My Key", { x: 0, y: 10, z: 0 });

var value = Settings.getValue("Script Example/My Key");
print("Value: " + (typeof value) + " " + JSON.stringify(value));  // object {"x":0,"y":10,"z":0}