A constant problem in LSL is the constant use of the same channel for
everything in scripts. This causes a fair deal of unnecessary
lag, and leads to many a server instability.
Ever wish you could create an arbitrary
channel that can be discovered by any script? You can!
The secret is converting a
key into a
channel in a predictable way. One tried and true method is to use the
hex provided.
Example code:
integer Key2Channel(key given, integer num_digits)
{
// Creates a private channel using a known key value given and num_digits
// Interestingly, you can find this number in any object by using a sensor
string known = (string)given;
integer count = llStringLength(known) - 1;
integer i;
string channel = ""; // String for channel creation
for(i = 0; i < count; i += 2)
{
channel += (string)((integer)("0x" + llGetSubString(known,i,i + 1)));
if(llStringLength(channel) >= num_digits)
i = count;
}
// Return the value
return (integer)channel;
}
integer Key2Integer(string input, integer start, integer chars)
{
return (integer)("0x"+llGetSubString(
(string)llParseString2List(input,["-"],[]),
start, start + chars - 1));
}
This trick also works with a script
pin for even more script-fu.