SL Persistent Data Storage

May 13, 2008 · Filed Under Second Life · 1 Comment 

The storage of persistent data appears to be quite a hot topic in the Second Life scripting community. I can certainly understand why. There are three options for storing data persistently in SL and each has a significant limitation.

  1. Object names and descriptions offer a location to read and write dynamic values, so long as they are short. Names are limited to 63 characters and descriptions to 127 characters. I’ve used the description field to store single values as well as short lists of values to parse in script.
  2. Notecards are a popular way to store configuration values for scripts. Packaging a no modify script with a modifiable notecard, allows sellers to offer scripts that are configurable without giving the source code away. However, notecards are read-only.
  3. Scripts can pass data to each other, allowing for scripts designed solely to store data while other scripts are reset. However, even these scripts will loose data when the sim is restarted.

Linden Labs has indicated that they are not pursuing a solution, at least not before the release of Mono, the upcoming scripting language for SL with increased speed and stability. There are third-party solutions, but privacy and reliability would be big concerns. There are scripts available to setup your own external storage via PHP. This requires a hosting solutions outside of SL, an additional cost for many SL residents.

In the mean time, it seems like the best compromise would be an API that utilizes a reliable third party provider of storage. For example, an open source API created with Google App Engine would allow each scripter to easily setup their own private storage. hmmm

SL Updating Scripts

May 6, 2008 · Filed Under Second Life · Comment 

When I started scripting in Second Life, I quickly realized that I would have many dozens of objects that used the same script. This script would need to be updated in all of those objects repeatedly, not something I was looking forward to doing manually. While it would be ideal if multiple objects could reference the same script from a single location, that option is not available.

The next best option was to push the updated script from a central script server object to the client objects. A single script could handle serving the script using llRemoteLoadScriptPin(). This function pushes the specified script to an object with a specified key. If all of the objects that needed the script had the same name, then the central script could query those objects by name and create a list of their keys.

Not so fast. There is no function to return a list of object keys based on name or any other criteria aside from linkage. Due to the distances involved, linking was not an option. I certainly didn’t want to maintain a list of keys for the objects manually. And of course, the client object getting the script would need to have a matching pin number set for llRemoteLoadScriptPin() to work. Both of these issues meant that a client script was also required.

It’s easy enough to set the pin in the client script using llSetRemoteAccessPin(). However, how would the server script get the key of the client object? The client script needs to provide it. Not unlike an HTTP or FTP request, the client would need to request the script via chat and the server object, listening for the request, could provide the requested script back to the requesting object.

This created another issue: How is the client request initiated for each of dozens of objects? I added a listener to the client script that would listen for a specific chat command from my avatar on a private channel. This way, I could update objects within 20 meters via chat or objects up to 100 meters away via shout. This system has worked fairly well and only requires about 3 shouts to update the client scripts scattered across an entire region.

I also considered creating a single point of activation at the server. This could be done by adding another listener to the server which would broadcast an update request region-wide, prompting all of the clients in the region to request an update.

  1. Avatar to Server: hey server, broadcast update request to region
  2. Server to Region: if you can hear me, it’s time to update
  3. Client to Server: hey server, please send me this script
  4. Server to Client: sends script

I didn’t have the need to implement this by the end of this project, but may do so right at the beginning of my next SL project.

I have also added code to each script that queries the object name and prevents of the script from running if it’s located on the script server. This will avoid potentially wacky behavior that might result from various scripts running on the server.

Second Life Simple Data Storage

April 24, 2008 · Filed Under Second Life · Comment 

In creating scripts for Second Life, I’ve tried to keep the scripts as portable and re-usable as possible. At the most basic level, this means creating a separation of code and data. For scripts that are used in a limited number of prims, this can be as simple as setting customizable variables at the top of the script. For scripts that are going to be used in many prims, this system requires maintaining a unique copy of each script in each prim. If your base script is updated to fix a bug or add a feature, you’ll need to update each script by hand or overwrite the script in prim and reset the custom variables. Both options are prone to error.

For scripts used in many prims, storing the data for those variables in the prim’s description field can be an effective solution. This allows you to replace the script without impacting the custom data in each prim. The description field is limited to 127 characters, so this method is only useful with short length data. Also, since the description field can be publicly viewed in prim properties, this method should not be used to store private or sensitive data. On the plus side, this data can be updated dynamically using llSetObjectDesc().

When storing the value of a single variable in the description field, use this code to retrieve the value. If the type is anything other than a string, simply prefix the function with the data type. In this case, the variable type is a vector.

vector myVector; //declare variable type
myVector = (vector)llGetObjectDesc(); //read the description, a string by default, and convert to a vector

If you need to store multiple values, format the data in the description field as a list, such as “Someplace;<72,89,25>”, read the data and parse it. This example uses the semi-colon as a delimiter.

list description;
string locationName;
vector locationTarget;

description = llParseString2List(llGetObjectDesc(), [";"], [""] );
locationName = llList2String(description, 0);
locationTarget = (vector)llList2String(description, 1);

I have found this method to be very effective and efficient for scripts that contain a limited amount of custom data. To store larger amounts of data, you’ll need to use a notecard or data store external to the prim.