Jump to content

Hi, how parse chat words ?


Baradar
 Share

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

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

Recommended Posts

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

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

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
 Share

×
×
  • Create New...