Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Passing part of a key through llRezObject() parameter

Garan Darkes
Registered User
Join date: 23 May 2006
Posts: 7
06-05-2007 06:34
I'm not sure if this has been posted before, but I've done my own little test with a possibility to pass on part of a key through the on_rez parameter. Here's what I came up with:



This script goes into the rezzer prim:

CODE

default
{
touch_start(integer total_number)
{
string tkey = (string)llGetOwner();
integer conv = (integer)("0x" + llGetSubString(tkey, 9, 12)); //convert second key section(after 1st dash) to a hex value.

llRezObject("Sphere", llGetPos() + <0, 0, 1>, ZERO_VECTOR, ZERO_ROTATION, conv);
}
}




This one goes into the prim that's to be rezzed:

CODE

string charset = "0123456789abcdef";

string int2chr(integer int) { // convert integer to unsigned charset
integer base = llStringLength(charset);
string out;
integer j;
if(int < 0) {
j = ((0x7FFFFFFF & int) % base) - (0x80000000 % base);
integer k = j % base;
int = (j / base) + ((0x7FFFFFFF & int) / base) - (0x80000000 / base);
out = llGetSubString(charset, k, k);
}
do
out = llGetSubString(charset, j = int % base, j) + out;
while(int /= base);
return out;
}

default
{
on_rez(integer param)
{
string keypart = int2chr(param);
llOwnerSay(keypart);
}


}




I tested it and it and the child prim did indeed return the same part of my key as was fed to the rezzer prim to begin with.

So for all of you who have been searching for a way to pass a key through the on_rez parameter so as to avoid listen lag, here's your solution. You can't pass a whole key, since the integer is a 32-bit field and a key is 128-bit. But this script passes down 4 characters which you can then compare in the script of the rezzed prim through llSubStringIndex().

There is an incredibly small chance that there will be 2 avatars/objects within sensor range who have the same key part after the same dash. So that worry should be safely ignored. But then, 4 hex digits only take 16 bits. So if you're really worried about it, you could pass up to 8 digits of the key to minimize this chance to practically non-existance.

Credit where credit is due: I pulled the conversion function off the wiki at: http://lslwiki.net/lslwiki/wakka.php?wakka=ExampleNumberConversion

The same seems to be doable with short strings if using the opposite function also listed on that wiki page in order to convert a string to an integer value. It only works with up to 6 characters though. It could still be used to pass on short text commands to the rezzed object.

Hope this helps.
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
06-05-2007 10:05
Another technique is to pass a randomly chosen channel number to the child in the rez parameter. Then, when the rezzer gets an object_rez event, have it send a message to the child, including the key passed to object_rez just to completely nail down who should get the message. You can then send as much information as you want.

There's also the fact that, in your example, the rezzed object could just call llGetOwner()... but I bet you're thinking of passing someone else's key.
Garan Darkes
Registered User
Join date: 23 May 2006
Posts: 7
06-05-2007 10:27
Yes, I just used my own key as an example.. Probably not the best example. But yes, this is intended to pass down the detected/predefined keys of others.

And I know of the say/listen communication trick. The point is that this is slow, uncertain and causes lag.. So the point would be to avoid listens if at all possible. This makes it possible to pass down a key without any extra communication whatsoever.. So if passing on a key is all you need, this would be perfect for the job.