The llLinksetDataWrite and llLinksetDataWriteProtected functions create or update a name:value pair in the linkset datastore. The linkset datastore is a semi-permanent key-value store that is retained as a prim property regardless of whether the script is deleted or reset (via manual reset, llResetScript, llResetOtherScript, or cloning the object). If value is an empty string, the pair is deleted.
This function returns 0 on success or an error code on failure.
When these functions are called, the linkset_data event is triggered in all scripts running in the linkset with an action of LINKSETDATA_UPDATE, or LINKSETDATA_DELETE if the pair is deleted.
The linkset datastore can contain up to 131072 bytes (128 KiB) of data and has no impact on script memory usage aside from the functions and events used to interact with it. Every pair written to the datastore consumes a number of bytes in the datastore equal to the length of name plus the length of value, plus an additional 32 bytes if written using llLinksetDataWriteProtected.
Creates or updates an unprotected name:value pair from the linkset's datastore.
integer llLinksetDataWrite( string name, string value );
Forced delay: 0 seconds. Energy: 10.0.
Returns an integer success or failure code.
Creates or updates a protected name:value pair from the linkset's datastore. Further attempts to read, write or update the name:value pair must use the protected versions of those functions and must supply the same string that was used in pass.
integer llLinksetDataWriteProtected( string name, string value, string pass );
Forced delay: 0.0 seconds. Energy: 10.0.
Returns an integer success or failure code.
| Constant | Description | |
|---|---|---|
| LINKSETDATA_OK | 0 | The name:value pair was written to the datastore. |
| LINKSETDATA_EMEMORY | 1 | A name:value pair was too large to write to the linkset datastore. |
| LINKSETDATA_ENOKEY | 2 | The name supplied to llLinksetDataWrite was empty. |
| LINKSETDATA_EPROTECTED | 3 | The name:value pair has been protected from overwrite in the linkset's datastore. |
| LINKSETDATA_NOTFOUND | 4 | The named key could not be found in the linkset's datastore when attempting to delete it. |
| LINKSETDATA_NOUPDATE | 5 | The name:value stored in the linkset was not changed by the write operation because the value stored matches the value written. |
default
{
touch_start(integer num_detected)
{
llLinksetDataWrite("test-name", "See you on the other side!");
llResetScript();
}
state_entry()
{
llOwnerSay(llLinksetDataRead("test-name")); // Should print "See you on the other side!" to the owner
}
}
// While there is no "standard" for names, it's a good idea to take some steps to prevent against other scripts accidentally overwriting your data.
// Since the datastore is shared among the entire linkset, one way to avoid name conflicts is to include the prim's UUID in the data pair's name.
// This example also monitors for llLinksetDataReset/unlinks and refreshes the datastore in response, which is usually good practice if you want to keep your data!
key this_uuid;
string lsd_data;
default
{
state_entry()
{
this_uuid = llGetKey(); // Save the current key into this_uuid for checking later
lsd_data = "bar"; // Store the data locally so it can be rewritten if the datastore gets erased for whatever reason
llLinksetDataWrite((string)llGetKey() + "-foo", lsd_data); // Write the data
}
on_rez(integer start_param)
{
if (llGetKey() != this_uuid)
{
// Prim UUID has changed!
// This should always be the case when on_rez is called, but is included here for clarity.
llLinksetDataWrite((string)llGetKey() + "-foo", llLinksetDataRead((string)this_uuid + "-foo")); // Read the data from the last prim UUID's pair and write it into this prim UUID's pair
// Note that you could also just write the lsd_data string instead of calling llLinksetDataRead, but this method is theoretically a little more robust if you expect other scripts to manipulate the data.
llLinksetDataDelete((string)this_uuid + "-foo"); // Erase the original data to free up memory
this_uuid = llGetKey(); // Update the UUID variable to the new UUID
}
}
linkset_data(integer action, string name, string value)
{
if (action == LINKSETDATA_UPDATE || action == LINKSETDATA_DELETE)
{
if (name == (string)llGetKey() + "-foo")
{
// Somebody else wrote to our pair - we'll just save it in case we need it later, but you could re-write the original data instead if desired.
lsd_data = value; // Note that in the case of LINKSETDATA_DELETE, value will be an empty string (""), which may or may not be how you want to handle that case
}
}
else if (action == LINKSETDATA_RESET)
{
// Linkset datastore has been reset!
llLinksetDataWrite((string)llGetKey() + "-foo", lsd_data); // Write the lsd_data string into this prim UUID's pair - in this case we can't use llLinksetDataRead because the datastore is empty
}
}
changed(integer change)
{
if (change & CHANGED_LINK)
{
// Linkset has changed!
// Generally, this can happen for a few reasons (see Caveats above), including when an avatar sits on the object. In certain circumstances, this resets the datastore.
// However, since the linkset data functions are very quick, it is easier to just write the data on every change to be safe for this example whether or not the datastore was reset.
llLinksetDataWrite((string)llGetKey() + "-foo", lsd_data); // Write the lsd_data string into this prim UUID's pair - in this case we can't use llLinksetDataRead because the datastore might be empty
}
}
}
integer gDialogChannel;
integer gDialogHandle;
integer gManagingBlocks;
startDialog(key person)
{
gManagingBlocks = 0;
gDialogHandle = llListen(gDialogChannel, "", person, "");
llDialog(person, "\nSelect action", ["List blocks", "Add block", "Remove block"], gDialogChannel);
llSetTimerEvent(60);
}
stopDialog()
{
llSetTimerEvent(0);
llListenRemove(gDialogHandle);
}
default
{
on_rez(integer sp)
{
llResetScript();
}
state_entry()
{
gDialogChannel = (integer)(llFrand(-10000000)-10000000);
llListen(PUBLIC_CHANNEL, "", NULL_KEY, "");;
}
timer()
{
stopDialog();
}
touch_start(integer nd)
{
key toucherKey = llDetectedKey(0);
if (toucherKey == llGetOwner())
{
startDialog(toucherKey);
}
}
listen(integer channel, string name, key id, string message)
{
if (llGetAgentSize(id) == ZERO_VECTOR)
{
return;
}
if (channel == gDialogChannel)
{
stopDialog();
if (gManagingBlocks)
{
message = llStringTrim(message, STRING_TRIM);
if ((key)message)
{
if (gManagingBlocks == 1)
{
llOwnerSay("Addition request has been sent to the blacklist storage");
llLinksetDataWrite("blocklist:" + message, "1");
}
else
{
llOwnerSay("Removal request has been sent to the blacklist storage.");
llLinksetDataDelete("blocklist:" + message);
}
}
else
{
llOwnerSay("The UUID '" + message + "' appears to be invalid.");
}
startDialog(id);
}
else if (message == "List blocks")
{
list blocks = llLinksetDataFindKeys("^blocklist:", 0, 0);
integer listLength = llGetListLength(blocks);
llOwnerSay("Blacklist items: " + (string)listLength);
integer i;
while (i < listLength)
{
string record = llGetSubString(llList2String(blocks, i), 10, -1);
llOwnerSay("- secondlife:///app/agent/" + record + "/about" + " - " + record);
++i;
}
blocks = [];
startDialog(id);
}
else if (message == "Add block" || message == "Remove block")
{
string label = "add to";
gManagingBlocks = 1;
if (message == "Remove block")
{
gManagingBlocks = 2;
label = "remove from";
}
gDialogHandle = llListen(gDialogChannel, "", id, "");
llTextBox(id, "\nPlease specify one single avatar UUID you'd like to " + label + " the blacklist storage.", gDialogChannel);
llSetTimerEvent(60);
}
return;
}
if (llGetListLength(llLinksetDataFindKeys("blocklist:" + (string)id, 0, 1)) > 0)
{
llRegionSayTo(id, 0, "You're blacklisted.");
return;
}
llRegionSayTo(id, 0, "Hello there, secondlife:///app/agent/" + (string)id + "/about - your message: " + message);
}
linkset_data(integer action, string name, string value)
{
if (action == LINKSETDATA_RESET || action == LINKSETDATA_DELETE || action == LINKSETDATA_UPDATE)
{
llOwnerSay("Blacklist storage modified.");
}
}
}