Jump to content

What is the math behind these unique channels for llListen


Guest
 Share

You are about to reply to a thread that has been inactive for 3443 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

A few months ago I learned how to create dialogs. I like that every user gets their own llListen channel based on their avatar key: http://wiki.secondlife.com/wiki/Dialog_Menus#Listening_to_Hear_the_User.27s_Choice

I tried to understand how this works exactly, so I created a little script to see what are the different ingrediants:

string avaChannel1;
string avaChannel2;
integer avaIntChannel1;
integer avaIntChannel2;
integer avaIntChannel3;

default
{
    state_entry()
    {
        
        avaChannel1 = llGetSubString( (string)llGetKey(), -7, -1);
        avaChannel2 = ("0x" + llGetSubString( (string)llGetKey(), -7, -1));
        avaIntChannel1 = (integer)avaChannel1;
        avaIntChannel2 = (integer)avaChannel2;
        avaIntChannel3 = (integer)("0x" + llGetSubString( (string)llGetKey(), -7, -1) );
        
    }

    touch_start(integer total_number)
    {
        llSay(0, avaChannel1);
        llSay(0, avaChannel2);
        llSay(0, (string)avaIntChannel1);
        llSay(0, (string)avaIntChannel2);
        llSay(0, (string)avaIntChannel3);
         llSay(0, llGetKey());
    }
}

 I got these 4 results:

Avatar Key: XXXXXXXX-XXXX-XXXX-XXX-XXXX2e227f4

avaChannel1: 2e227f4

avaChannel2: 0x2e227f4

avaIntChannel1: 2

avaIntChannel2: 48375796

avaIntChannel3: 48375796

 

What is the Maths behind this? Why is string "avaChannel1" typcasted into the integer "2" and an a very similar string with the addition of "0x" into the integer "48375796"? How are letters typcasted into integers anyway?

Link to comment
Share on other sites

You are learning how to deal with hexadecimal numbers -- numbers in base 16.  First, you have captured the last seven characters of a key (which is a special sort of string).  If you try to convert that to a base 10 integer, as you did with avaIntChannel1, you'll find that the conversion only works until you run out of integer characters in the string.  That's why you get the answer "2".  Anything after that in the string is a non-numerical character  -- nonsense in base 10.   By adding the string "0x" to the start, though, you have said, "Oh, everything after this is meant to be read as a hexadecimal number."  So, then avaIntChannel2 is what you get when you convert that hexadecimal number to a decimal (base 10) number.  And of course avaIntChannel3 is the same thing, except that you got there directly. 

 

Link to comment
Share on other sites

"Typecasting" is the action of redefining one type of variable as another --  in this case, casting a string as an integer.  Whether the integer is base 10 (decimal) or base 16 (hexadecimal), it's still an integer.  You can convert an integer with one base to an integer with another base, but that's not typecasting, since you start and end with the same type of variable.  It's more than a semantic difference.  All three of your avaInt variables are integers, for example.  The typecasting only took place when you converted that initial substring.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3443 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...