Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to detect a wrod within a phrase?

Animations Pfeffer
Registered User
Join date: 29 Jul 2007
Posts: 99
08-02-2007 09:37
Hello

Im trying to find a word (from a list) in a phrase.

At the moment i have this example, but need to find if the words appears anywhere in the phrase:

listen(integer channel, string name, key id, string message)
{
if (llListFindList(mnuWords, [message]) != -1)
{
curEmote = llList2String(mnuEmotes, llListFindList(mnuWords, [message]));
llStartAnimation(curEmote);
}
}

How can achieve this?

O want the possibility to set my name in the list and find if anyone says my name in the middle of any phrase and then trigger some specific Emote according to some index, like in the example showed.

Thanks in advance.
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
08-02-2007 09:47
try: integer llSubStringIndex(string source, string pattern)

listen(integer channel, string name, key id, string message)
{
if (llSubStringIndex(message, "Animations Pfeffer";) != -1)
{
llSay(0,name + ", you said my name!"
}
}

The previous example is not looking for 1 message like you are (your name) and uses the same index for the animation as that of the discovered word. In your case since you look for one word only you have no basis to select an animation from a list so might consider using a randomly generated number?
Animations Pfeffer
Registered User
Join date: 29 Jul 2007
Posts: 99
08-02-2007 09:57
Thnaks for your answer. :)

What im looking exaclty is to associate different names with different facil expression, more or less like in the example i use. But need to find it in the middle of the expression.

Lets say that my lastname Pfeffer is associated with the express_laugh, so i need to find if anywhere in a phrase someone says any of the words in the list, find which and then i could find the corresponding emote as in the exmaple im using.

I hope i make myself clear because english is not my main language he he
Animations Pfeffer
Registered User
Join date: 29 Jul 2007
Posts: 99
08-02-2007 10:03
Lets say i want to achieve this:

integer channel = 0;
string curEmote;

list mnuWords = ["Pfeffer", "Animations"];

list mnuEmotes = ["express_afraid", "express_afraid_emote"];

default {
state_entry()
{
llListen(channel, "", llGetOwner(), "";);
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}

on_rez(integer total_number)
{
llResetScript();
}

listen(integer channel, string name, key id, string message)
{
if (llListFindList(mnuWords, [message]) != -1)
{
curEmote = llList2String(mnuEmotes, llListFindList(mnuWords, [message]));
llStartAnimation(curEmote);
}
}
}


But the problem is that with this example it only works if the user only write my name or lastname alone, but not in the middle of a phrase.
I want to find it in a phrase, identify which one was and trigger the associated emote.
Thraxis Epsilon
Registered User
Join date: 31 Aug 2005
Posts: 211
08-02-2007 10:12
integer channel = 0;
string curEmote;

list mnuWords = ["Pfeffer", "Animations"];
list mnuEmotes = ["express_afraid", "express_afraid_emote"];

default
{
state_entry()
{
llListen(channel, "", llGetOwner(), "";);
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);

}

on_rez(integer total_number)
{
llResetScript();
}

listen(integer channel, string name, key id, string message)
{
list params = llParseString2List(message,[" "],[]);
if (llListFindList(mnuWords, param ) != -1)
{
curEmote = llList2String(mnuEmotes, llListFindList(mnuWords, params));
llStartAnimation(curEmote);

}
}
}