Baradar Posted May 10, 2011 Share Posted May 10, 2011 Hi guys, How parse chat words ? Examples: <object_name> up, <object_name> down Thanks for help Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted May 10, 2011 Share Posted May 10, 2011 There are different ways to do it - what you choose depends on the use case. Basically, most of the involve either searching a string for the next occurence of a sub-string or parsing a string into a list and then searching the list. Link to comment Share on other sites More sharing options...
Baradar Posted May 10, 2011 Author Share Posted May 10, 2011 awesome =) Thank you Link to comment Share on other sites More sharing options...
Void Singer Posted May 10, 2011 Share Posted May 10, 2011 a horribly over simplified example: default{ state_entry(){ llListen( 1, "", "", "" ); } listen( integer Channel, string Name, key Source, string Message ){ if (llSubStringIndex( Message, llGetObjectName() ) == 0){ //--- message starts with the objects name list MessageList = llParseString2List( Message, [" "], [] ); //-- turn the message into a list, broken up by spaces if (llList2String( MessageList, 1 ) == "On"){ //-- second element is "On" llOwnerSay( "I was turned on" ); }else if (llList2String( MessageList, 1 ) == "Off"){ //-- second element is "Off" llOwnerSay( "I was turned off" ); } } }} the above example would be triggered by "/1<object name> On" or "/1<object name> Off" but will fail if the user doesn't use the exact capitalization, or puts any spaces before the object name the below example ignores those, and uses indexes from list find to tell it what to do... string gStrNom;default{ state_entry(){ gStrNom = llToLower( llGetObjectName() ); llListen( 1, "", "", "" ); } listen( integer vIntChn, string vStrNom, key vKeySrc, string vStrMsg ){ //-- !llGetSubstring, means it must start with the string we're looking for if (!llSubStringIndex( vStrMsg = llToLower( llStringTrim( vStrMsg, STRING_TRIM ) ), gStrNom ){ //-- we also saved the modified string back to itself, so we don't have to modify it again //-- check if the second part of the text (which is now lowercased) is on or off, and save the index. the result is -1 when not found integer vIntTst = llListFindList( ["off", "on"], [llList2String( llParseString2List( vStrMsg, [" "], [] ), 1)] ); if (~vIntTst){ //-- false if vIntTst is -1, meaning it wasn't found llOwnerSay( "I was turned " + llList2String( ["Off", "On"], vIntTst );//-- use the same indexes to find the mesage to send, so we only need one call to llOwnerSay to do the work of two } } }} 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