# Linkset Data

> lsl.dev (unofficial LSL docs). Full API: https://lsl.dev/api.json · Index for LLMs: https://lsl.dev/llms.txt

> The linkset datastore: 128 KiB of key-value pairs kept in the object, protected keys, searching and the linkset_data event.

Linkset data is a key-value store kept in the object itself, shared by every script in the linkset. It is the usual place for an object's own persistent state. Part of the [Data Storage](/features/data-storage/) feature.

## Concepts

- The store holds up to 128 KiB of string **name:value** pairs and does not use script memory
  - It survives script resets, deletion of the script and cloning the object
  - Each pair costs the UTF-8 length of name plus value, and 32 bytes more if protected; [`llLinksetDataAvailable`](/functions/llLinksetDataAvailable/) gives the bytes left
- [Write](/functions/llLinksetDataWrite/) creates or updates a pair, [read](/functions/llLinksetDataRead/) returns its value, [delete](/functions/llLinksetDataDelete/) removes it
  - Writing an empty value deletes the pair
  - Writes return a [result code](/constants/groups/LinksetDataError/) such as [`LINKSETDATA_OK`](/constants/LINKSETDATA_OK/) or [`LINKSETDATA_EMEMORY`](/constants/LINKSETDATA_EMEMORY/)
  - Many small keys are cheaper than reading and rewriting one large value
- [Protected pairs](/functions/llLinksetDataWriteProtected/) need the same **pass** to [read](/functions/llLinksetDataReadProtected/), update or [delete](/functions/llLinksetDataDeleteProtected/)
  - The value of a protected pair is not sent in `linkset_data`
- Keys can be [listed](/functions/llLinksetDataListKeys/) alphabetically and [counted](/functions/llLinksetDataCountKeys/)
  - [Find](/functions/llLinksetDataFindKeys/), [count](/functions/llLinksetDataCountFound/) and [delete](/functions/llLinksetDataDeleteFound/) keys matching a regular expression, so prefixes like `cfg:` group related keys
- [`llLinksetDataReset`](/functions/llLinksetDataReset/) erases everything, protected pairs included
- Every change raises [`linkset_data`](/events/linkset_data/) in all scripts of the linkset, with the [action](/constants/groups/LinksetDataAction/), the **name** and the new **value**

## Functions and events

- `integer` [`llLinksetDataWrite`](/functions/llLinksetDataWrite/) `(string name, string value)`
- `string` [`llLinksetDataRead`](/functions/llLinksetDataRead/) `(string name)`
- `integer` [`llLinksetDataDelete`](/functions/llLinksetDataDelete/) `(string name)`
- `integer` [`llLinksetDataWriteProtected`](/functions/llLinksetDataWriteProtected/) `(string name, string value, string pass)`
- `list` [`llLinksetDataFindKeys`](/functions/llLinksetDataFindKeys/) `(string pattern, integer start, integer count)`
- `integer` [`llLinksetDataAvailable`](/functions/llLinksetDataAvailable/) `()`
- `event` [`linkset_data`](/events/linkset_data/) `(integer action, string name, string value)`

## Scripting Details

- `integer` [`llLinksetDataWrite`](/functions/llLinksetDataWrite/) `(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.
- `string` [`llLinksetDataRead`](/functions/llLinksetDataRead/) `(string name)`: Reads and returns the string value corresponding to key name from the linkset's datastore.
- `integer` [`llLinksetDataDelete`](/functions/llLinksetDataDelete/) `(string name)`: Deletes the unprotected key-value pair specified by name from the linkset's datastore, triggering a linkset_data event.
- `integer` [`llLinksetDataWriteProtected`](/functions/llLinksetDataWriteProtected/) `(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.
- `string` [`llLinksetDataReadProtected`](/functions/llLinksetDataReadProtected/) `(string name, string pass)`: Reads and returns the string value of the protected key name from the linkset's datastore using the passphrase pass.
- `integer` [`llLinksetDataDeleteProtected`](/functions/llLinksetDataDeleteProtected/) `(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.
- `list` [`llLinksetDataFindKeys`](/functions/llLinksetDataFindKeys/) `(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).
- `list` [`llLinksetDataListKeys`](/functions/llLinksetDataListKeys/) `(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).
- `integer` [`llLinksetDataCountKeys`](/functions/llLinksetDataCountKeys/) `()`: Returns an integer representing the total number of unique keys stored in the linkset's datastore.
- `integer` [`llLinksetDataCountFound`](/functions/llLinksetDataCountFound/) `(string pattern)`: Returns the total count of keys in the linkset datastore that match the regular expression pattern.
- `list` [`llLinksetDataDeleteFound`](/functions/llLinksetDataDeleteFound/) `(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.
- `integer` [`llLinksetDataAvailable`](/functions/llLinksetDataAvailable/) `()`: Returns an integer representing the number of bytes available/remaining in the linkset's datastore.
- `void` [`llLinksetDataReset`](/functions/llLinksetDataReset/) `()`: 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.
- `event` [`linkset_data`](/events/linkset_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.

## Example

```lsl
default
{
    touch_start(integer num_detected)
    {
        integer count = (integer)llLinksetDataRead("touches") + 1;
        llLinksetDataWrite("touches", (string)count);
    }

    linkset_data(integer action, string name, string value)
    {
        if (action == LINKSETDATA_UPDATE && name == "touches")
            llSetText("Touched " + value + " times", <1, 1, 1>, 1);
    }
}
```

## Constant groups

Constant groups: [LinksetDataAction](/constants/groups/LinksetDataAction/) (4), [LinksetDataError](/constants/groups/LinksetDataError/) (6)

## Related

See also: [Data Storage](/features/data-storage/), [Linkset Data](/categories/linkset_data/), [Linkset data (Second Life Wiki)](https://wiki.secondlife.com/wiki/Linkset_data), [Guide: linkset resources (reusable prims in linkset data)](/guides/link-numbers/#linkset-resources)

## Related features

- [Data Storage](/features/data-storage/)
- [Linksets](/features/linkset/)
- [Data Transmission](/features/data-transmission/)

## Categories

- [Linkset Data](/categories/linkset_data/)

---

From lsl.dev: https://lsl.dev/features/data-storage/linkset-data/
