Skip to content
lsl.devlsl.devLSL Dev

Data Storage

Script memory is small and lost on reset, so larger or longer-lived scripts store data elsewhere. Each store has a different size, lifetime, speed and audience.

As a rule: linkset data for an object’s own persistent state, experience key-value storage for data shared across objects and regions, notecards for read-only configuration, and an external server through HTTP for anything bigger.

Concepts

  • Script memory: global variables persist until the script resets
  • Linkset data: up to 128 KiB of string key-value pairs stored in the object, readable and writable by every script in it
    • It survives script resets, taking the object into inventory and rezzing it again
    • Keys can be protected with a password
    • Spreading data across many keys is cheaper than reading and rewriting one large value
    • Changes are reported in the linkset_data event
  • Experience persistent storage: scripts compiled to an experience share a key-value store that any object in that experience can use, anywhere on the grid
    • Every call is asynchronous and answers in the dataserver event
  • Notecards are read-only text in the object’s inventory, good for configuration that users edit by hand
  • Object properties hold small values
  • External storage: for large or shared data, send it to a web service and fetch it back when needed

Functions and events

integerllLinksetDataWrite(string name, string value)
stringllLinksetDataRead(string name)
eventlinkset_data(integer action, string name, string value)
keyllCreateKeyValue(string k, string v)
keyllReadKeyValue(string k)
eventdataserver(key queryid, string data)
stringllGetNotecardLineSync(string name, integer line)
keyllGetNotecardLine(string name, integer line)
integerllGetFreeMemory()
stringllGetStartString()

Linkset data

Persistent per-object storage shared by all its scripts, with optional password protection per key (wiki guide).

Script memory

Globals live until reset; a script can lower its own limit (wiki guide).

Scripting Details

integerllGetFreeMemory()
Returns an integer representing the number of free bytes of memory currently available to the script.
integerllGetUsedMemory()
Returns an integer representing the total number of bytes of memory currently used by the script (non-Mono scripts always return 16,384 bytes).
integerllGetSPMaxMemory()
Returns an integer representing the maximum memory (in bytes) used by the script while the memory profiler was last active (only valid after using PROFILE_SCRIPT_MEMORY).
integerllGetMemoryLimit()
Returns an integer representing the maximum memory limit (in bytes) that the script is allowed to allocate.
integerllSetMemoryLimit(integer limit)
Requests that limit bytes are reserved for the script. Returns TRUE on success or FALSE on failure (has no effect in LSO).
integerllLinksetDataWrite(string name, string value)
Creates or updates an unprotected key-value pair (name and value) in the linkset's datastore. Returns an integer success or failure code.
stringllLinksetDataRead(string name)
Reads and returns the string value corresponding to key name from the linkset's datastore.
integerllLinksetDataDelete(string name)
Deletes the unprotected key-value pair specified by name from the linkset's datastore, triggering a linkset_data event.
integerllLinksetDataWriteProtected(string name, string value, string pass)
Creates or updates a protected key-value pair (name and value) in the linkset's datastore using the passphrase pass. Returns an integer success or failure code.
stringllLinksetDataReadProtected(string name, string pass)
Reads and returns the string value of the protected key name from the linkset's datastore using the passphrase pass.
integerllLinksetDataDeleteProtected(string name, string pass)
Deletes the protected key-value pair specified by name from the linkset's datastore using the passphrase pass, triggering a linkset_data event.
listllLinksetDataFindKeys(string pattern, integer start, integer count)
Returns an alphabetically sorted list of up to count keys from the datastore that match the regular expression pattern, starting at index start (returns all matching keys if count < 1).
listllLinksetDataListKeys(integer start, integer count)
Returns an alphabetically sorted list of up to count keys from the datastore, starting at index start (returns all keys if count < 1).
integerllLinksetDataCountKeys()
Returns an integer representing the total number of unique keys stored in the linkset's datastore.
integerllLinksetDataCountFound(string pattern)
Returns the total count of keys in the linkset datastore that match the regular expression pattern.
listllLinksetDataDeleteFound(string pattern, string pass)
Deletes all keys in the datastore matching the regular expression pattern. Returns a list [num_deleted, num_failed_protected]. Decrypts and deletes protected keys if matching pass is provided.
integerllLinksetDataAvailable()
Returns an integer representing the number of bytes available/remaining in the linkset's datastore.
voidllLinksetDataReset()
Erases all key-value pairs stored in the linkset's datastore, triggering a linkset_data event (with LINKSETDATA_RESET) in all scripts in the linkset.
eventlinkset_data(integer action, string name, string value)
Fires in all scripts in the linkset whenever the datastore has been modified via an llLinksetData function. Passes the action taken, the affected key name, and the new value.
keyllCreateKeyValue(string k, string v)
Starts an asynchronous transaction to create a key-value pair (k and v) associated with the script's experience. Returns a key query handle for the dataserver event. Fails with XP_ERROR_STORAGE_EXCEPTION if the key already exists.
keyllReadKeyValue(string k)
Starts an asynchronous transaction to read the value associated with key k in the experience. Returns a key query handle for the dataserver event. Fails with XP_ERROR_KEY_NOT_FOUND if the key does not exist.
keyllUpdateKeyValue(string k, string v, integer checked, string original_value)
Starts an asynchronous transaction to update the key k to value v inside the experience datastore. If checked is TRUE, the update fails with XP_ERROR_RETRY_UPDATE unless the existing value matches original_value.
keyllDeleteKeyValue(string k)
Starts an asynchronous transaction to delete the key-value pair associated with key k in the experience. Returns a key query handle for the dataserver event.
keyllKeysKeyValue(integer first, integer count)
Starts an asynchronous transaction to retrieve count keys from the experience data store starting at the zero-based index first. Returns a key query handle for the dataserver event. Fails with XP_ERROR_KEY_NOT_FOUND if out of bounds.
keyllKeyCountKeyValue()
Starts an asynchronous transaction requesting the total count of keys in the experience data store. Returns a key query handle for the dataserver event.
keyllDataSizeKeyValue()
Starts an asynchronous transaction to request the used and total data storage allocated for the experience. Returns a key query handle for the dataserver event.
eventdataserver(key queryid, string data)
Triggered when requested data is returned to the script (e.g., from llRequestAgentData, llRequestInventoryData, or llGetNotecardLine).
stringllGetNotecardLineSync(string name, integer line)
Synchronously reads the line index line of the notecard name from the region's cache, immediately returning its text without raising a dataserver event. Returns 'NAK' if not cached or 'EOF' if out of bounds.
keyllGetNotecardLine(string name, integer line)
Asynchronously requests the line index line of the notecard name from the dataserver. Returns a key query handle for the dataserver event, which will return 'EOF' when reaching past the end of the notecard.
keyllGetNumberOfNotecardLines(string name)
Asynchronously requests the total line count of the notecard name. Returns a key query handle for the dataserver event.
listllFindNotecardTextSync(string name, string pattern, integer start, integer count, list options)
Synchronously searches a cached notecard name for lines containing pattern, returning a list of line and column numbers. Returns a list containing 'NAK' if the notecard is not cached, or an empty list if no matches are found.
voidllSetObjectDesc(string description)
Sets the description of the prim containing the script to description (limited to 127 characters).
stringllGetObjectDesc()
Returns a string containing the description of the specific prim containing the script.
voidllSetObjectName(string name)
Sets the name of the prim containing the script to name.
stringllGetObjectName()
Returns a string containing the name of the specific prim containing the script.
integerllGetStartParameter()
Returns an integer representing the start/rez parameter passed to the object on creation (returns 0 if rezzed by an agent).
stringllGetStartString()
Returns the initialization string passed to the object's root prim on rez with llRezObjectWithParams (via REZ_PARAM_STRING; returns an empty string if rezzed by an agent).
keyllHTTPRequest(string url, list parameters, string body)
Sends an HTTP request to the specified url containing body and configured via parameters. Raises an http_response event and returns a key query handle identifying the request.
eventhttp_response(key request_id, integer status, list metadata, string body)
Triggered when an HTTP response body is received for a pending request_id, or if the request fails or times out.

Additional

Constant groups LinksetDataAction 4LinksetDataError 6ExperienceError 19

See also SL Wiki LSL Script MemoryCategory Linkset DataSL Wiki Linkset dataFeature ExperienceCategory Experience DataCategory NotecardFeature InventorySL Wiki LSL NotecardFeature PrimsFeature CommunicationsFeature Data TransmissionPage Guide: linkset resources (reusable prims in linkset data)Planned Guide: choosing where to store data