My script is not behaving the way I expected. I would appreciate if an advanced scripter could take a look at this script: key request_id;
integer listen_handle;
integer indexOfFirstIsLetterBefore;
integer indexofFirstLetterAfter;
string beforeIs;
string afterIs;
default
{
state_entry()
{
llSay(0, "Hello everyone. My name is AI Doll Demo Version 1. I was created by Erin Grayman. Please tell me a simple sentence containing the word 'is' in channel 77.");
listen_handle = llListen(77, "", llDetectedKey(0), " is ");
}
listen(integer channel, string name, key id, string msg)
{
//Get the index of the character before the space in " is ".
indexofFirstLetterAfter = (llSubStringIndex(msg, " is "))+4;
indexOfFirstIsLetterBefore = (llSubStringIndex(msg, " is "))-1;
beforeIs = llGetSubString(msg, 0, indexOfFirstIsLetterBefore);
afterIs = llGetSubString(msg, indexofFirstLetterAfter, llStringLength(msg)-1);
if (llSubStringIndex(beforeIs, " is ") == -1 && llSubStringIndex(beforeIs, " is ") == -1)
{
if (llSubStringIndex(beforeIs, ".") != -1 || llSubStringIndex(beforeIs, ",") != -1 || llSubStringIndex(beforeIs, "!") != -1 || llSubStringIndex(beforeIs, "?") != -1)
{
llSay(0, "Please state a very simple sentence.");
}
else
{
list my_list = llParseString2List(beforeIs,[" "],["."]);
integer myListIndexThe = llListFindList(my_list, ["The"]);
my_list = llDeleteSubList(my_list, myListIndexThe, myListIndexThe);
integer myListIndexA1 = llListFindList(my_list, ["A "]);
my_list = llDeleteSubList(my_list, myListIndexA1, myListIndexA1);
integer myListIndexA2 = llListFindList(my_list, ["a "]);
my_list = llDeleteSubList(my_list, myListIndexA2, myListIndexA2);
integer myListIndexLThe = llListFindList(my_list, ["the "]);
my_list = llDeleteSubList(my_list, myListIndexLThe, myListIndexLThe);
integer myListIndexMy = llListFindList(my_list, ["My "]);
my_list = llDeleteSubList(my_list, myListIndexMy, myListIndexMy);
integer myListIndexLMy = llListFindList(my_list, ["my "]);
my_list = llDeleteSubList(my_list, myListIndexLMy, myListIndexLMy);
integer myListIndexHis = llListFindList(my_list, ["His "]);
my_list = llDeleteSubList(my_list, myListIndexHis, myListIndexHis);
integer myListIndexLHis = llListFindList(my_list, ["his "]);
my_list = llDeleteSubList(my_list, myListIndexLHis, myListIndexLHis);
integer myListIndexHer = llListFindList(my_list, ["Her "]);
my_list = llDeleteSubList(my_list, myListIndexHer, myListIndexHer);
integer myListIndexLHer = llListFindList(my_list, ["her "]);
my_list = llDeleteSubList(my_list, myListIndexLHer, myListIndexLHer);
integer myListIndexThat = llListFindList(my_list, ["That "]);
my_list = llDeleteSubList(my_list, myListIndexThat, myListIndexThat);
integer myListIndexLThat = llListFindList(my_list, ["that "]);
my_list = llDeleteSubList(my_list, myListIndexLThat, myListIndexLThat);
integer myListIndexLAny = llListFindList(my_list, ["any "]);
my_list = llDeleteSubList(my_list, myListIndexLAny, myListIndexLAny);
integer myListIndexAny = llListFindList(my_list, ["Any "]);
list my_final_list = llDeleteSubList(my_list, myListIndexAny, myListIndexAny);
string final_Before_Is = llDumpList2String(my_final_list, " ");
if (llSubStringIndex(final_Before_Is, "sl") != -1)
{
llInstantMessage(id, "I love sl as much as you do, but I cannot process that abbreviation. ^^");
}
//Done parsing text before "is."
list my_list_after = llParseString2List(afterIs,[" "],["."]);
integer myListAfterIndexA = llListFindList(my_list_after, ["a"]);
my_list_after = llDeleteSubList(my_list_after, myListAfterIndexA, myListAfterIndexA);
integer myListAfterIndexThe = llListFindList(my_list_after, ["the"]);
my_list_after = llDeleteSubList(my_list_after, myListAfterIndexThe, myListAfterIndexThe);
integer myListAfterIndexPeriods = llListFindList(my_list_after, ["..."]);
my_list_after = llDeleteSubList(my_list_after, myListAfterIndexPeriods, myListAfterIndexPeriods);
integer myListAfterIndexPeriod = llListFindList(my_list_after, ["."]);
list my_final_list_after = llDeleteSubList(my_list_after, myListAfterIndexPeriod, myListAfterIndexPeriod);
string final_After_Is = llDumpList2String(my_final_list_after, " ");
//Make the request.
request_id = llHTTPRequest("http://www.thesaurus.com/browse/" + final_Before_Is, [HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/x-www-form-urlencoded"], final_After_Is);
}
}
else
{
llInstantMessage(id, "Please input a sentence with one 'is'.");
}
//Count backwards from that space using
//uSubStringLastIndex(string source, string patternToLookFor);
//llSubStringIndex returns index
//of first pattern instance in source.
//
}
http_response(key requestid, integer status, list metadata, string body)
{
if(request_id == requestid)
{
llSay(0, "I think the sentence last inputted to me was a definition or equivalence, and not an analogy or description.");
}
else
{
llSay(0, "I think the sentence last inputted to me was an analogy or descripting, and not a definition or equivalence.");
}
llSleep(5.0);
llSay(0, "Thank you for chatting with me! I hope to talk again soon. Please tell my creator Erin Grayman if I am working correctly ;)");
}
}