Jump to content

Is there a way to detect the last stated message within the public channel (0) ?


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

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

Recommended Posts

Posted

For example, if the public chat has a last recorded message saying "hello world" could a script detect this somehow to be used in scripting?

A more clear example.. if the chat is like this:

1: hey how are you

2: im great wbu?

3: awesome, thanks!

(event in script will then trigger)

--

I want to make a script that will constantly detect the last stated message on the public channel until it hits the correct string that will trigger an event in the script. For the sake of the example, lets assume the string its parsing for in each last stated message is "awesome, thanks!". Once the last stated message is "awesome, thanks!" an event will trigger within the script...

Is this actually possible? thanks

Posted (edited)

A script can register a listen-event on (one or more) chat channels with llListen.

If you want the script to only trigger the listen event on exactly the message "awesome, thanks!" you can register a listener like so:

llListen(PUBLIC_CHANNEL, "", "", "awesome, thanks!");

The above code will make the script

  • listen to anyone (no name or key constraint)
  • on the public chat channel (0)
  • saying the message "awesome, thanks!"
    • It will not accept "awesome thanks"
    • It will not accept "Awesome, thanks!"
    • It won't even accept "That's awesome, thanks!"
    • The message must match exactly.

Instead, what you probably want is:

llListen(PUBLIC_CHANNEL, "", "", "");

Now, the above code will make the script

  • listen to anyone
  • on the public channel
  • saying any message

So, a listen event will trigger for every message. But that's okay. You can then start parsing the chat message to see if your wanted message is in there. For example:

listen(integer channel, string name, key id, string message)
{
    // channel: WHERE the message was heard
    // name:    the avatar or object's NAME
    // id:      the avatar or object's KEY (uuid)
    // message: the actual TEXT content

    // Make all the text lowercase, so the input-case no longer matters.
    message = llToLower(message);

    // Search for an exact "awesome, thanks" from the message.
    // The index will be -1 if it wasn't found anywhere.
    integer index = llSubStringIndex(message, "awesome, thanks");

    if (index != -1)
    {
        llOwnerSay(name + " said it!");
    }
}

You can complicate it further by searching for the words "awesome" and "thanks" separately, and even making sure that the word "awesome" comes before "thanks." Make sure to read the wiki often. It really is your friend, even though some pages can be a bit much to take in.

http://wiki.secondlife.com/wiki/llToLower
http://wiki.secondlife.com/wiki/llSubStringIndex
http://wiki.secondlife.com/wiki/llOwnerSay
http://wiki.secondlife.com/wiki/llSay

P.S. You can of course write 0 instead of PUBLIC_CHANNEL. I used that constant just for clarity.

Edited by Wulfie Reanimator
  • Like 1
Posted (edited)
1 hour ago, Wulfie Reanimator said:

A script can register a listen-event on (one or more) chat channels with llListen.

If you want the script to only trigger the listen event on exactly the message "awesome, thanks!" you can register a listener like so:


llListen(PUBLIC_CHANNEL, "", "", "awesome, thanks!");

The above code will make the script

  • listen to anyone (no name or key constraint)
  • on the public chat channel (0)
  • saying the message "awesome, thanks!"
    • It will not accept "awesome thanks"
    • It will not accept "Awesome, thanks!"
    • It won't even accept "That's awesome, thanks!"
    • The message must match exactly.

Instead, what you probably want is:


llListen(PUBLIC_CHANNEL, "", "", "");

Now, the above code will make the script

  • listen to anyone
  • on the public channel
  • saying any message

So, a listen event will trigger for every message. But that's okay. You can then start parsing the chat message to see if your wanted message is in there. For example:


listen(integer channel, string name, key id, string message)
{
    // channel: WHERE the message was heard
    // name:    the avatar or object's NAME
    // id:      the avatar or object's KEY (uuid)
    // message: the actual TEXT content

    // Make all the text lowercase, so the input-case no longer matters.
    message = llToLower(message);

    // Search for an exact "awesome, thanks" from the message.
    // The index will be -1 if it wasn't found anywhere.
    integer index = llSubStringIndex(message, "awesome, thanks");

    if (index != -1)
    {
        llOwnerSay(name + " said it!");
    }
}

You can complicate it further by searching for the words "awesome" and "thanks" separately, and even making sure that the word "awesome" comes before "thanks." Make sure to read the wiki often. It really is your friend, even though some pages can be a bit much to take in.

http://wiki.secondlife.com/wiki/llToLower
http://wiki.secondlife.com/wiki/llSubStringIndex
http://wiki.secondlife.com/wiki/llOwnerSay
http://wiki.secondlife.com/wiki/llSay

P.S. You can of course write 0 instead of PUBLIC_CHANNEL. I used that constant just for clarity.

what if I want to detect a message coming from the same object or is this possible

Edited by Torisu10
rewrite
You are about to reply to a thread that has been inactive for 1595 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
×
×
  • Create New...