Jump to content

http_response and group names


Emilee Edenflower
 Share

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

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

Recommended Posts

Hi so I've never posted here before but I've made a few scripts in the past (though not for about 2 years, so I'm a bit out of practice!)

Anyway, I've been trying to update an old HUD of mine which can scan a region as one of its functions, and return a list of names plus how far away the avi is - eg: Emilee Edenflower [96m]

What I want to do now is add the group name of the detect avi to that output. I've pieced together a script (from various other topics on this forum, so it probably needs tidying up later!) which can get the group name from someone clicking on an item, which is all good and well if I just want to print out info into chat. But what I can't seem to figure out is how to get the variables made in http_response back into other output.

Here's my script so far (for just detecting group names). You'll see at the end, http_response makes a variable called groupname which is output via llSay and llSetText. But I want to be able to use this variable elsewhere in the script. Is it possible to create a function I can pass the URL and group UUID to which contains the http_response and return the groupname as the functions return value and assign it to a variable to be use within other strings?

// Get the active group from the avatar specified by inAvatar.
// return the group key, a NULL_KEY is returned if the group 
// cannot be determined
key
getAvatarGroup (key inAvatar)
{
    key result = NULL_KEY;
 
    // get the the list of attachments for the avatar 
    list parts = llGetAttachedList (inAvatar);
    if (llGetListLength (parts) > 0)
    {
         // If the avatar has any attachments then just get the 
         // group key for the first attachment.
         list parts2 = llGetObjectDetails (llList2Key (parts, 0), [OBJECT_GROUP]);  
         result = llList2Key (parts2, 0);
    }
 
    return (result);
}
 
 string groupname;
// ------------------------------------------
 
default
{
 
    touch_start (integer total_number)
    {
        key av = llDetectedKey (0);
        key groupId = getAvatarGroup (av);
        //list dets = llGetObjectDetails(llGetKey(),[OBJECT_GROUP]);
        //key uuid = llList2Key(dets,0);
        string url = "http://world.secondlife.com/group/"+(string)groupId;
        //llInstantMessage (av, "group = " + (string) groupId);
        llSay(0,llGetDisplayName(llDetectedKey(0)) + " is in the group...");
        llHTTPRequest(url,[],"");
        llReleaseURL(url);
        llSay(0,groupname);
        
    }
    state_entry()
    {
        //604f9b3c-a72f-a7a1-421a-3f5d83037218 -> Xoco Reborn (2)
        llSetText("Touch me!",<255,255,255>,1.0);
   }
          
	http_response(key id, integer status, list data, string body)
    {
        list parsed = llParseString2List(body,["<title>","</title>"],[]);
        string groupname = llList2String(parsed,1);
        list parsedname = llParseString2List(groupname,[],["&lt;","&rt;","&quote;","&amp;","&cent;","&pound;","&yen;","&eu;","&copy;","&reg;"]);
        integer len = llGetListLength(parsedname);
        integer i;
        list replace = ["&lt;","<","&rt;",">","&quote;","\"","&amp;","&","&cent;","¢","&pound;","£","&yen;","¥","&euro;","€","&copy;","©","&reg;","®"];
        for(i = 0;i < len;i++)
        {
            string substring = llList2String(parsedname,i);
            integer idx = llListFindList(replace,[substring]);
            if(~idx && !(idx%2))
            {
                parsedname = llListReplaceList(parsedname,llList2List(replace,idx+1,idx+1),i,i);
            }
        }
        groupname = llDumpList2String(parsedname,"");
        llSetText("Last group detected: "+groupname,<255,255,255>,1.0);
        llSay(0,groupname);
    }
    
    
}

 

Edited by Emilee Edenflower
Link to comment
Share on other sites

You have already created groupname as a global string variable, so you may already use it elsewhere in the script with no further magic.  Well, almost none.....  You'll have to remove the word string from the start of this line in  your http_response event:

string groupname = llList2String(parsed,1);

After all, by having the word string there, you are creating a second, local variable named groupname that will take the place of the one that you already created as a global variable.  You definitely don't want to do that.

Oh, and you'll also want to remove the line 

1 hour ago, Emilee Edenflower said:

llSay(0,groupname);

from the end of your touch_start event, since your script won't know what to llSay until it finishes the work in the http_response event.  That's where you finally know what groupname is. 

Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...