Jump to content

Merging two scripts - another project (linking SL to Pandorabots)


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

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

Recommended Posts

Hello again.  I have another project where I am trying to merge two scripts.  I have revived an old project of mine which links an object (chatbot) in SL to an AI engine in Pandorabots after I found my original pandorabot was still active.

In the SL script library I found a script for pandorabots (in 2 parts)  that works fine.  I have customised this script to pass some data about the avatar talking to the bot which will enhance the conversation.  Currently it passes the avatar's name and location when the avatar first starts talking to the bot.  You can test this by creating an object and putting in the two scripts (script1 and script2) as posted below.

What I am attempting to do is to also collect the avatar's rez date.  For this I have found another script in the library that can determine an avatar's age which included a RequestAgentData call and dataserver event to process the data.

It would seem logical to do the dataserver process in touch_start before the call to the pandorabot but I get a syntax error whatever way I try this.  I know I have this part of the script in the wrong place currently but at least it saves without any syntax errors.  I have included the avatar age script as well which works perfectly fine by itself so you can see where I've pulled the age script from.

Any suggestions how I can restructure my script to get this working.

If you do create an object with these scripts in, then you can talk to the bot and hopefully you'll get some intelligent answers back - I'll do more work on that side of things once I've got this problem solved.  After starting a conversation with the bot by touching it, typing 'testinit' (without quotes) will show the values of these initial variables so you would be able to see if any changes to the script worked.

Thank you in advance for any suggestions.

Script 1:

// :CATEGORY:ChatBot
// :NAME:Pandora_Chatbot
// :AUTHOR:Destiny Niles
// :CREATED:2010-01-10 05:20:56.000
// :EDITED:2013-09-18 15:38:59
// :ID:603
// :NUM:826
// :REV:1.0
// :WORLD:Second Life
// :DESCRIPTION:
// An ALICE base chatbot hosted at Pandorabots.com
//
//
// Place these two scripts in an object. The first one is the listener for you to customize and control who it listens to. The second one is the actual engine itself.
// :CODE:
string mesg;
key gOwner;
list talkers;

key Query;   // added by SG for use with age calc
integer uYr;  // added by SG for use with age calc
integer uMn;  // added by SG for use with age calc
integer uDy;  // added by SG for use with age calc


listen_to(key talker)

{

        integer index = llListFindList( talkers, [talker] );

    if ( index != -1 )

        {

        talkers = llDeleteSubList(talkers, index, index);

         llMessageLinked(LINK_SET,0,"BYE",talker);

        }

    else

        {

        talkers = talkers + talker;
        string aviName = llDetectedName(0);
        string location =  llList2String(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_NAME]) ,0);
        string region = llGetRegionName();
        
  // The MessageLinked below is formatted to process the information in Pandorabots collected from SL - i.e. name and location.  Trying to also include avatars rez day but this part not working yet.  You can check this by saying in chat (after logging in by touching the prim containing these 2 scripts) "testinit" (without the quotes)  
      
      llMessageLinked(LINK_SET,0,"CTRL1 "+aviName+". "+"CTRL2 "+(string)uYr+" "+(string)uMn+" "+(string)uDy+". " +    "CTRL3 "+location+". "+"CTRL6 "+region+".",talker);
        }

}

default

{    

    state_entry()    

    {

        gOwner = llGetOwner();

        llListen(0,"",NULL_KEY,"");

    }

    on_rez(integer i)

    {

        llWhisper(0,"Owner say /chat or touch me");

        llResetScript();

    }

    touch_start(integer num_detected)
    
    {
     Query = llRequestAgentData(llDetectedKey(0),DATA_BORN);
     listen_to(llDetectedKey(0));
     }   

 dataserver(key QID,string Data)
    {
        if (QID == Query)
        {
           
            float YrDays = 365.25;
            float MnDays = YrDays / 12;
            
            // This is the user's birthdate.
            integer uYr = (integer)llGetSubString(Data,0,3);
            integer uMn = (integer)llGetSubString(Data,5,6);
            integer uDy = (integer)llGetSubString(Data,8,9);

            float uXVal = (uYr * YrDays) + (uMn * MnDays) + uDy;
            
                     
            // This is today's date
            Data = llGetDate();
            integer Yr = (integer)llGetSubString(Data,0,3);
            integer Mn = (integer)llGetSubString(Data,5,6);
            integer Dy = (integer)llGetSubString(Data,8,9);

            float XVal = (Yr * YrDays) + (Mn * MnDays) + Dy;
            
                       
             // We calculate the difference between those two dates to get the number of days.
            integer DDiff = (integer)(XVal - uXVal);
           //  llSay(0,"total days in SL:"+(string)DDiff);
            
            integer years = (integer)(DDiff/YrDays);
          //  llSay(0,"years:"+(string)years);
            
            integer months =  (integer)((DDiff - (years*365.25))/MnDays);
          //   llSay(0,"months:"+(string)months);
            
           integer days = llRound((((DDiff - (years*365.25))/MnDays) - months) *MnDays);
         //  llSay(0,"days:"+(string)days);
          }
          }  

            listen(integer channel, string name, key id, string msg)

    {

        if (msg == "/chat")

        {

            listen_to(id);

            return;

        }

        if ((msg == "/reset") && (id == gOwner))

        {

            llWhisper(0,"Resetting");

            llResetScript();

        }

        integer index = llListFindList( talkers, [id] );

        if (index != -1)

        {

            mesg = llToLower(msg);

            llMessageLinked(LINK_SET,0,msg,id);

        }

    }

}

Script 2

// :CATEGORY:ChatBot
// :NAME:Pandora_Chatbot
// :AUTHOR:Destiny Niles
// :CREATED:2010-01-10 05:20:56.000
// :EDITED:2013-09-18 15:38:59
// :ID:603
// :NUM:827
// :REV:1.0
// :WORLD:Second Life
// :DESCRIPTION:
// pandorabot script
// :CODE:
key requestid;

string botid;

string cust;

string reply;

string newreply;

integer that_begin;

integer that_end;

integer cust_begin;

list params;

 

string SearchAndReplace(string input, string old, string new)

{

   return llDumpList2String(llParseString2List(input, [old], []), new);

}

 

default

{

    state_entry()

    {

        cust="";

        botid="c058b3671e368866";  // this id is specific to SG's bot

    }

 

    on_rez(integer param)

    {

        llResetScript();

    }

 

    link_message(integer sender_num, integer num, string msg, key id)

    {

        requestid = llHTTPRequest("http://www.pandorabots.com/pandora/talk-xml?botid="+botid+"&input="+llEscapeURL(msg)+"&custid="+cust,params,"");

    }

    http_response(key request_id, integer status, list metadata, string body)

    {

        if (request_id == requestid)

        {

            cust_begin=llSubStringIndex(body, "custid=");

            cust=llGetSubString(body, cust_begin+8, cust_begin+23);

            that_begin = llSubStringIndex(body, "<that>");

            that_end = llSubStringIndex(body, "</that>");
            reply = llGetSubString(body, that_begin + 6, that_end - 1);

            newreply = SearchAndReplace(reply, "%20", " ");

            reply = newreply;

            newreply = SearchAndReplace(reply,"&quot;","\"");

            reply = newreply;

            newreply = SearchAndReplace(reply,"&lt;br&gt;","\n");
            reply = newreply;

            newreply = SearchAndReplace(reply, "&gt;", ">");

            reply = newreply;

            newreply = SearchAndReplace(reply, "&lt;", "<");
            

            llSay(0,newreply);

        }

    }

}

Avatar's age calc script

key Query;

default
{
    
    on_rez(integer X) {llResetScript();}
    
    touch_start(integer X)
    {
              Query = llRequestAgentData(llDetectedKey(0),DATA_BORN);
    }
    
    dataserver(key QID,string Data)
    {
        if (QID == Query)
        {
            // The following variables are set to account for leap years and assume
            // the days evenly distributed amongst the 12 months of a year.
            float YrDays = 365.25;
            float MnDays = YrDays / 12;
            

            // This is the user's birthdate.
            integer uYr = (integer)llGetSubString(Data,0,3);
            integer uMn = (integer)llGetSubString(Data,5,6);
            integer uDy = (integer)llGetSubString(Data,8,9);

            float uXVal = (uYr * YrDays) + (uMn * MnDays) + uDy;
           
            // This is today's date
            Data = llGetDate();
            integer Yr = (integer)llGetSubString(Data,0,3);
            integer Mn = (integer)llGetSubString(Data,5,6);
            integer Dy = (integer)llGetSubString(Data,8,9);
           
            float XVal = (Yr * YrDays) + (Mn * MnDays) + Dy;

            // We calculate the difference between those two dates to get the number of days.
            integer DDiff = (integer)(XVal - uXVal);

            llSay(0,"total days in SL:"+(string)DDiff);
            
            integer years = (integer)(DDiff/YrDays);
            llSay(0,"years:"+(string)years);
            
            integer months =  (integer)((DDiff - (years*365.25))/MnDays);
            llSay(0,"months:"+(string)months);
            
           integer days = llRound((((DDiff - (years*365.25))/MnDays) - months) *MnDays);
           llSay(0,"days:"+(string)days);
            
        }
    }
}

 

Thanks

 

Link to post
Share on other sites

Well, the data returned in the dataserver event is just a string of the rezzdate. No need to do any calculations with it. 

This is script 1.

// :CATEGORY:ChatBot
// :NAME:Pandora_Chatbot
// :AUTHOR:Destiny Niles
// :CREATED:2010-01-10 05:20:56.000
// :EDITED:2013-09-18 15:38:59
// :ID:603
// :NUM:826
// :REV:1.0
// :WORLD:Second Life
// :DESCRIPTION:
// An ALICE base chatbot hosted at Pandorabots.com
//
//
// Place these two scripts in an object. The first one is the listener for you to customize and control who it listens to. The second one is the actual engine itself.
// :CODE:
string mesg;
key gOwner;
list talkers;

key Query;   // added by SG for use with age calc
key avi;
string aviName;
string RezDate;
string location;
string region;

listen_to(key talker)
{
    integer index = llListFindList( talkers, [talker] );
    if ( index != -1 )
    {
        talkers = llDeleteSubList(talkers, index, index);
        llMessageLinked(LINK_SET,0,"BYE",talker);
    }
    else
    {
        talkers = talkers + talker;
        // The MessageLinked below is formatted to process the information in Pandorabots collected from SL - i.e. name and location.  Trying to also include avatars rez day but this part not working yet.  You can check this by saying in chat (after logging in by touching the prim containing these 2 scripts) "testinit" (without the quotes)  
        llMessageLinked(LINK_SET, 0, "CTRL1 " + aviName + ". " + "CTRL2 " + RezDate + ". " + "CTRL3 " + location + ". " + "CTRL6 " + region + ".", talker);
    }
}

default
{    
    state_entry()    
    {
        gOwner = llGetOwner();
        llListen(0,"",NULL_KEY,"");
    }
    on_rez(integer i)
    {
        llWhisper(0,"Owner say /chat or touch me");
        llResetScript();
    }
    touch_start(integer num_detected)
    {
        avi = llDetectedKey(0);
        aviName = llDetectedName(0);
        location =  llList2String(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_NAME]) ,0);
        region = llGetRegionName();
        Query = llRequestAgentData(llDetectedKey(0), DATA_BORN);
    }   
    dataserver(key QID,string Data)
    {
        if (QID == Query)
        {
            RezDate = Data;
            listen_to(avi);
        }
    }  
    listen(integer channel, string name, key id, string msg)
    {
        if (msg == "/chat")
        {
            listen_to(id);
            return;
        }
        if ((msg == "/reset") && (id == gOwner))
        {
            llWhisper(0,"Resetting");
            llResetScript();
        }
        integer index = llListFindList( talkers, [id] );
        if (index != -1)
        {
            mesg = llToLower(msg);
            llMessageLinked(LINK_SET,0,msg,id);
        }
    }
}

In script 2 I didn't change anything.
The avatar age thing I threw away.

Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 626 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
×
×
  • Create New...