Aeryn Brooks Posted November 8, 2012 Share Posted November 8, 2012 I want to make a mood ring that listens to words you say in open chat. For example, when the wearer says "I'm happy to see you!" I want the ring to turn blue because it heard the wearer say "happy." The problem I'm having is coming up with a system where there are several lists with several key words (Happy: happy, smiles, laughs / Sad: sad, frowns, cries / etc.). I know I need to use llSubStringIndex, but I honestly have no idea how it works. Can anyone help me please? Link to comment Share on other sites More sharing options...
xigaro Posted November 8, 2012 Share Posted November 8, 2012 Nice idea It sounds like it could cause a fair bit of lag. Listening to channel 0 is discouraged because of the CPU time required to process every public chat line. If you're just setting llListen() to listen to the ring owner, that helps. I would break the chat line into a list using llParseString2List(). This gives you two lists - one with keywords, one with words used in the chat line. Now I'd loop through one list with a for() loop, and compare each list item to the other list using llListFindList(). Try to loop through the smaller list. If you're only using 3 or 4 keywords then loop through your keywords list. If you have a dozen or more then loop through the chat line list. There might be a more efficient way of doing it, if there is I hope someone can post Hope that helps Link to comment Share on other sites More sharing options...
Rolig Loon Posted November 8, 2012 Share Posted November 8, 2012 if (~llSubStringIndex (llToLower(message),"happy")){ llSay(0,"I heard the word \"happy\");} and so forth. This is a very laggy project. You'll have to keep a listener open on the public chat channel all the time (never a good idea) and you'll have to evaluate every single thing that anybody says with a stack of tests like that one, looking to see if the message contains one of your key words. You're probably not going to be very popular on your sim. Link to comment Share on other sites More sharing options...
Xiija Posted November 9, 2012 Share Posted November 9, 2012 This will listen to the owner, just an example of comparing lists... you can put this in a box and try iy out ..turns red for angry, blue for happy will search owners chat for keywords in your 2 lists compare code is from VoidSinger you could also use notecards and data event to hold the lists.. (P.S. ...it wont differentiate if someone says "im not very happy"... ) /*//-- Anti-License Text --//*//*// Contributed Freely to the Public Domain without limitation. //*//*// 2012 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*//*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/integer uListFindAnyFirst( list vLstSrc, list vLstTst ){ return ~(~( llParseString2List( llList2String( llParseStringKeepNulls( llDumpList2String( vLstSrc, "•" ), vLstTst, [] ), 0 ), ["•"], [] ) != []) % ~(vLstSrc != []));}integer k;integer x;integer y;integer handle;list happyMoods;list angryMoods;default{ state_entry() { happyMoods = ["happy","fine"]; angryMoods = ["mad","pissed"]; } touch_start(integer total_number) { k = !k; if(k) { llOwnerSay("On"); handle = llListen(0, "", llGetOwner(), ""); } else { llOwnerSay("Off"); llListenRemove(handle); } } listen( integer channel, string name, key id, string message ) { if (message) { list heard = llParseString2List(llToLower(message),[" "],[""]); x = uListFindAnyFirst(happyMoods,heard); y = uListFindAnyFirst(angryMoods,heard); if (~x) { llSetColor(<0, 0, 1>, ALL_SIDES); } else if (~y) { llSetColor(<1, 0, 0>, ALL_SIDES); } } }} Link to comment Share on other sites More sharing options...
Recommended Posts
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