Avatar UUID (key) to Integer
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
08-15-2009 12:26
heyas;
i thought i saw somewhere, in passing, some script doing something to convert an avatar uuid to an integer for use as a chat channel, so the avatar's possessions could talk to each other on it, without much interference with other chat traffic.
anyhow, was wondering if anyone heard of such a thing, has such a formula and is willing to share, etc. ? or can make one up? or.... something?
_____________________
Why Johnny Can't Rotate: http://forums.secondlife.com/showthread.php?t=94705
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
08-15-2009 12:51
From: Bloodsong Termagant heyas;
i thought i saw somewhere, in passing, some script doing something to convert an avatar uuid to an integer for use as a chat channel, so the avatar's possessions could talk to each other on it, without much interference with other chat traffic.
anyhow, was wondering if anyone heard of such a thing, has such a formula and is willing to share, etc. ? or can make one up? or.... something? (integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)); will do it. Or you can use any channel you like and say listen(integer channel, string name, key id, string msg) { if(llGetOwnerKey(id)==llGetOwner()){//if whatever is talking to me either belongs to my owner or is my owner } }
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
08-15-2009 13:06
Try this. It just grabs the first 8 characters in a key and converts it from a hex number to a channel ... integer CHAN; integer hex2int(string hex) { return(integer)("0x"+hex); } default { state_entry() { CHAN = hex2int(llGetSubString(llGetOwner(),0,7)); if (CHAN < 0) { CHAN = -CHAN; } llListen(CHAN,"",llGetOwner(),""); llOwnerSay("Please send me a test message on channel " + (string)CHAN + " to verify this method."); }
listen(integer channel,string name, key id,string message) { llOwnerSay("I just received your message on channel " + (string)CHAN + "."); } }
ETA: LOL.... Innula is quicker than I was. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Lance Corrimal
I don't do stupid.
Join date: 9 Jun 2006
Posts: 877
|
08-16-2009 10:48
i have a snippet somewhere that simply strips all non-numeric chars from an UUID and then calculates a modulo maxint.
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-16-2009 12:26
From: Lance Corrimal i have a snippet somewhere that simply strips all non-numeric chars from an UUID and then calculates a modulo maxint. For all intents and purposes that's what the scripts above do as well. Especially the one that takes the last 8 characters rather than the first, but really it shouldn't matter much which you sample: AFAIK SL UUIDs are generated very randomly rather than being based partially on things like hardware identification of a computer (see http://en.wikipedia.org/wiki/UUID).
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
08-16-2009 14:13
heyas;
very cool!
i was wondering, because it isnt clear from a small sample... will those 8 places ALWAYS convert to a number that is within the limits of the # of chat channels?
thanks guys!
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
08-16-2009 14:50
The largest 8-digit hex number, converted to an integer, is still an order of magnitude smaller than the maximum of 2,147,483,647 allowed for a channel number. That's pretty safe.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
08-16-2009 15:42
From: Rolig Loon The largest 8-digit hex number, converted to an integer, is still an order of magnitude smaller than the maximum of 2,147,483,647 allowed for a channel number. That's pretty safe. Actually, an 8 digit hex number has 32 bits, so can get up to 2^32-1 (4,294,967,295). MAXINT (2,147,483,647) is 2^31-1. It doesn't really matter, though, because it's a signed number, not unsigned. Numbers over MAXINT will just flip over to the range (-2^31 .. -1), and map into negative chat channels. You can't express an integer that's not a legal chat channel number, because the range is just the range of signed 32-bit integers.
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
08-16-2009 17:18
::stares blearily::
ummm... that's good!
maxint huh? hmm...
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-16-2009 17:22
From: Bloodsong Termagant heyas;
very cool!
i was wondering, because it isnt clear from a small sample... will those 8 places ALWAYS convert to a number that is within the limits of the # of chat channels?
thanks guys! No. It is possible you'll get -2^31, which is DEBUG_CHANNEL. You can't use it for normal communication. You could check for it if you really wanted. While you're at it you could also check for zero. Some things just shouldn't be said on public chat. But the chances are pretty darn good you won't get those. Two out of four billion is pretty negligible if you ask me.
|
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
08-17-2009 07:57
I generally use a function like: integer channel = 0; integer t = 0; do channel = (integer)("0x" + llGetSubString( llMD5String((string)llGetOwner(), t++), 0, 7 ); while (((channel >= 0) && (channel <= 9999)) || (channel == DEBUG_CHANNEL)); You'll notice the first clause in the while rejects values between 0 and 9999, this is mainly because of the number of devices which, as a part of their user interface, assign listens to channels like /1, or /1234 (the two most common I think).
_____________________
Computer (Mac Pro): 2 x Quad Core 3.2ghz Xeon 10gb DDR2 800mhz FB-DIMMS 4 x 750gb, 32mb cache hard-drives (RAID-0/striped) NVidia GeForce 8800GT (512mb)
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
08-17-2009 09:18
From: Haravikk Mistral I generally use a function like: integer channel = 0; integer t = 0; do channel = (integer)("0x" + llGetSubString( llMD5String((string)llGetOwner(), t++), 0, 7 ); while (((channel >= 0) && (channel <= 9999)) || (channel == DEBUG_CHANNEL)); I realize it's astronomically unlikely that this would be a problem, but that loop is NOT guaranteed to terminate. 
|
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
08-17-2009 09:23
From: Argent Stonecutter I realize it's astronomically unlikely that this would be a problem, but that loop is NOT guaranteed to terminate.  Ah whoops, it's also not the exact statement I use, should have posted: integer channel = (integer)("0x" + llGetSubString( llMD5String((string)llGetOwner(), t++), 0, 7 ));
while (((channel >= 0) && (channel <= 9999)) || (channel == DEBUG_CHANNEL)) ++channel;
_____________________
Computer (Mac Pro): 2 x Quad Core 3.2ghz Xeon 10gb DDR2 800mhz FB-DIMMS 4 x 750gb, 32mb cache hard-drives (RAID-0/striped) NVidia GeForce 8800GT (512mb)
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-17-2009 09:37
From: Haravikk Mistral Ah whoops, it's also not the exact statement I use, should have posted Actually the first version was better. You're not going to get an infinite loop. And in the second version, you're increasing the possibility of channel 10000 quite a bit and might as well do it without a loop. If you're worried about infinite loops in random number generation, check out this commonly used algorithm for choosing random values with a normal distribution: http://en.wikipedia.org/wiki/Marsaglia_polar_methodThat's likely to repeat a lot more than your random channel generating loop. Heh.
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
08-17-2009 09:41
Still not guaranteed to terminate, and yes the first version was better.  As a thought experiment: integer t = 0; integer channel = 0; for(t = 0; channel in range && t < 20; t++) channel = ....; if(t >= 20) state inconceivable;
Where state inconceivable says something like "you just did 20 MD5 calculations in a row and they were all under 10,000... time to hop on a plane to vegas.  "
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-17-2009 10:27
From: Argent Stonecutter Still not guaranteed to terminate... I'll guarantee it will terminate. Chances are every one of us will be hit by meteorites before it will go through the loop more than 10 times or so. In fact, I bet chances are better that a memory failure or system error causes the whole sim to hang than that the logic does. 
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
08-17-2009 14:17
From: Hewee Zetkin I'll guarantee it will terminate. You're mixing up "ensure" and "insure". 
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-17-2009 15:42
From: Argent Stonecutter You're mixing up "ensure" and "insure".  LOL. I'll give you that one.
|