Jump to content

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


Recommended Posts

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

Link to post
Share on other sites

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
Link to post
Share on other sites
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
Link to post
Share on other sites
8 hours ago, Torisu10 said:

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

Read the llListen caveats:

  • A prim cannot hear/listen to chat it generates. It can, however, hear a linked prim.
    • Chat indirectly generated (as a result of llDialog, llTextBox or from a linked prim) can be heard if in range.

See also:

http://wiki.secondlife.com/wiki/LlMessageLinked

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...