The description field of primitives in Second Life can be used as a decent variable storage field. While, upon a reset of a script, which may happen during a region restart, all the variables in a script get reset and data is lost, the description field can provide a persistent data storage. The description field is limited to 127
characters, which is sufficient to store variables such as flags or script settings.
The variables in the primitive description are a &
-separated list of keys to values bound by the equal sign.
For example, suppose two variables "test" and "start" have their values mapped to "1", respectively "now". Then the primitive description will be:
test=1&start=now
The choice of syntax tried to avoid interference with LSL types. LSL has an llList2CSV
function that is able to encode a list to a comma-separated string. However, the problem with that is that vectors in LSL use the comma in order to separate the components and would thus interfere with the precedence of a comma-separated list. Since we use the equal sign (=
) and the ampersand sign (&
), this guarantees that we do not interfere with LSL types.
127
bytes. Trying to write more to the description field will yield a "description overflow" error on the DEBUG_CHANNEL
.=
) and the ampersand sign (&
) are used for the syntax, they are not allowed within variables.\n
) nor the pipe operator (|
). When saved to the description field, they will be turned into the question mark sign (?
).Getting a variable:
wasKeyValueGet("test", llGetObjectDesc());
will return the value of the variable "test" from the primitive description.
Setting a variable:
llSetObjectDesc(wasKeyValueSet("test", "1", llGetObjectDesc()));
will set the value of the variable "test" to "1" in the primitive description.
The source and usage examples may be found on the key-value data page.