I got this question from Osiris:

What good options are there for saving persistent data, given that we can’t write to notecards and list data will be lost at reset?

Ach.  LSL is sadly lacking in provisions for the storage of persistent data, to tell the truth.  Storing any data outside of the script’s own memory is a pain, no matter how you go about it.  It’s possible, of course, but such solutions are not typically elegant.

The first technique, and the easiest, is to use prim color/alpha to store your data. If the data you’re storing can be converted to an integer (such as a boolean value for options), float, or vector, you can store a pretty decent amount of data with this.  I use an invisible root prim (invisible as in an alpha layer texture, not an alpha value), and cut that sucker up to get as many faces as I can out of it (which can be a decent number with a properly tortured torus).  For each face, you can store up to 4 numeric values (more if you’re clever) or one vector and one number.

For instance, if you wanted to store this list of values: [10, 28.4, 0.1, 5] you’d use something like this to store the data:

StoreData(integer face, list values) {
vector temp_color =  * 0.01;
llSetPrimitiveParams([PRIM_COLOR,face,temp_color,llList2Float(values,3) * 0.01]);
}

and something like this to retrieve it:

list retrieved(integer face) {
list params = llGetPrimitiveParams([PRIM_COLOR,face]);
vector temp_color = llList2Vector(params,0) * 100;
return [temp_color.x,temp_color.y,temp_color.z,llList2Float(params,3)*100];
}

After being stored and retrieved, the value it will return is this: 9.999999, 28.700001, 0.100000, 0.000000.

Now, you’ll notice that this isn’t quite right. There is some tiny data corruption during LSL’s calculations (because LSL is like that) so that’s a possibility you’d have to prepare for (usually by simply rounding). If you need exacting data to the fourth or fifth decimal place, you’re looking at some ugly hacks or a different technique.

You’d be amazed what you can store in this form, by the way. Use integers to hold places in lists (if you have a hardcoded list of values, you can store the current value as an integer), or store locations as vectors (divided by 1000 or so, though, as color vectors are all 1.0 or under). Generally, this is best for storing simple integer values, however, as the llRound() function can take care of slightly off-true LSL calculations.

The second technique is more difficult but considerably more reliable and flexible, and that is to use an off-world server. There are a few ways of doing this:

  1. W-Hat httpDB - I’ve never used this service, but it seems pretty simple.  You can store data in key/value pairs on W-Hat’s servers and retrieve it.  There’s some pretty simple documentation on this usage on the website.  The upside is that it doesn’t require your own server setup; the downside is that it requires you to rely on somebody else’s.
  2. Silo - Zero Linden created an interesting sort of off-world data storage system, which is posted on the wiki.  Silo doesn’t use a database; rather, it creates simple text files in a series of nested folders and allows you to store/request data from them using llHTTPRequest.  It’s a good way to store data simply and without a database on your own web server.  It’s a little outdated, but it’s simple enough (python-based, if I remember correctly) that it should still work just fine.  The upside is that it’s easy enough to implement without knowing PHP, and the downside is that it’s not as stable or easy to back up as a database.
  3. Database - The last, and the best solution (if you have the experience to use it) is implementing your own database.  This requires, however, some knowledge of simple PHP/MySQL (or other database protocol).  If there seems to be a strong interest, I might consider whipping up a portable system for this along with some instructions for implementing it on your own server.

All in all, LSL is particularly unfriendly to those looking to store persistent data, but with a little cleverness, you can find ways.  If you have a good way I’ve not listed here, I’d love to hear from you in the comments.