Change font size
It is currently Wed May 22, 2019 10:28 pm

Forum rules


Post a new topicPost a reply Page 1 of 1   [ 1 post ]
Author Message
 Post subject: Generate an integer from a UUID
PostPosted: Wed Sep 29, 2010 3:19 pm 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 391
Location: England UK
The script below was something i wrote as I needed to create a Listen channel specific to an avatar for a HUD. In the past I had used a method where either the HUD or the object had listened on a default channel, then upon activation or whatever the HUD or object would generate a random channel number, then 'say' the number to the object or HUD, then both would just use that channel to keep it private (stop crosstalk to other scripts). If the channel number was to be verified then it would require a listener in both the HUD and object. That worked pretty well, but always seemed a bit much to just generate a private channel, so I came up with the script, which in essence seems to be a lot more efficient, at least in the amount of code was required for generating a private channel.

The details of how it works are commented in the script.

//UUID to integer by Adelle Fitzgerald. Please use as you like and if you do use it an attribution to myself would be nice, but not necessary.

//Piece of code to generate an integer from a UUID. The UUID is broken down and then each numerical character is added together, the alpha characters are convetred to their equivelant hex number. To get around the problem of two UUIDs having the same characters but in a different order (which would result in the same value) each number is multiplied by its place in order, so the first number is multiplied by 0, the 2nd number by 1, the third number by 2 and so on for all 36 characters. The script treats the "-" as 0.

//Its a bit rough, but it works and there should be very little chance of two UUIDs generating the same number.

key uuid;
integer debug = FALSE; //Change to TRUE for some chat noise ;-)
integer myInt;

        //uuid = llGetOwner();
        uuid = "aa009299-0c22-47c0-9cd4-aa518f0274a7"; //The UUID. Can be any avatars UUID, or object, or whatever
        integer i;
        for (i = 0; i < 36; i++) //Loop through each of the UUID characters
            if (debug) llSay(0,(llGetSubString((string)uuid,i,i)));
            string str = llGetSubString((string)uuid,i,i); //Take each character and if it is not an actual number, convert it to a number
            if (str == "a") str = "10";
            else if (str == "b") str = "11";
            else if (str == "c") str = "12";
            else if (str == "d") str = "13";
            else if (str == "e") str = "14";
            else if (str == "f") str = "15";
            integer num = (integer)str * i; //Multiply the number by its place in the UUID
            if (debug) llSay(0,str + " * " + (string)i + " = " + (string)num);
            myInt += num; //Add them together
        llSay(0,(string)myInt); //Give the result

"Nothing lasts forever; It's scientific"
~David Byrne (Talking Heads)

Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 1 post ]

Who is online

Users browsing this forum: legacy_majestic-12 [bot] and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of