Trouble using the llListfindList function
|
|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
09-28-2006 18:21
I'm experimenting with lists to just get a feel for them. what I want to do is have my script look at a list of "words" and if something is said from that list to respond with a say. My understand of llListFindList says my script should work just fine, but it doesn't. It does work if I only use a single item in the filter's list. default { state_entry() { llListen( 0, "", llGetOwner(), "" ); }
listen( integer channel, string name, key id, string message ) { message=llToLower(message); list filter1=[":d", ":)", ">:)", ":(", ":'(", ";)", ":p"]; //Words we are looking for list speech = llParseString2List(message, [" "], []); integer found=llListFindList(speech,filter1); if (found>=0) { llSay(0,"You used a smiley"); } speech = []; } }
_____________________
My SLExchange shopTypos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work.
|
|
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
|
09-28-2006 18:25
llList2List returns a sublist
You want
llListFindList
|
|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
09-28-2006 18:54
From: Aakanaar LaSalle llList2List returns a sublist
You want
llListFindList edited my typo and added some clarification.
_____________________
My SLExchange shopTypos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work.
|
|
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
|
09-28-2006 21:20
in the llListFindList reverse your parameters. it should be source first (this is the list you're testing against, the filters in this case) then the Test (the list you're looking for) Also, when you parse2string, you are indeed taking that string and turning it into a list. in this case, at the spaces with the spaces taken out. This is good. But if someone says, for example them:  Then the speach will end up being ["  ", "  "] if both items exist and are next to each other and in that order in the filters, the ListFindList will return the position of the first one. If both items exist but arn't next to each other or are reversed order, the ListFindList will return -1. If either of the two do not exit.. again ListFindList will return -1 So if this behaviour is what you're wanting, then leave it as is.. otherwise You may want to seperate out only one list item to check. Perhaps you're looking for it at the end of a sentance? Then use llList2List(speach, -1, -1) to grab the last element.
|
|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
09-28-2006 22:47
From: Aakanaar LaSalle in the llListFindList reverse your parameters. it should be source first (this is the list you're testing against, the filters in this case) then the Test (the list you're looking for) The wiki says to have them in the order I have them in. I tried switching them around and still the script doesn't find anyhing I use in my filter. From: someone If both items exist but arn't next to each other or are reversed order, the ListFindList will return -1.
This property may be causing me my problem. From: someone You may want to seperate out only one list item to check. I was hoping to avoid this as it would require me to write a 'if' statement for everything I want to check- the end application that I'm thinking of using this in is going to use around 50 such keywords. That's a lot of 'if' statements to write and I was hoping for a much smaller section of code.
_____________________
My SLExchange shopTypos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
09-29-2006 00:51
From: Senuka Harbinger The wiki says to have them in the order I have them in. I tried switching them around and still the script doesn't find anyhing I use in my filter. Aakanaar LaSalle was correct. In this case the filter would actually be what you are checking against not the list of possible matches. I know it sound counter intuative but its a conceptual issue. Your filtering the speech against a known list, not the other way around. For it to work correctly you will need to check each word in the entered text for a match like this : default { state_entry() { llListen( 0, "", llGetOwner(), "" ); }
listen( integer channel, string name, key id, string message ) { message=llToLower(message); list filter1=[":d", ":)", ">:)", ":(", ":'(", ";)", ":p"]; //Words we are looking for list speech = llParseString2List(message, [" "], []); integer len = llGetListlength(speech); integer found = 0; integer i; for(i = 0; i < len; i++) { string str = llList2String(speech,i); integer filtered =llListFindList(filter1,[ str ]); if (filtered >=0) ++found; } if (found >=0) { llSay(0,"You used a smiley"); } speech = []; } }
|
|
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
|
09-29-2006 01:14
From: someone From: someone You may want to seperate out only one list item to check.
I was hoping to avoid this as it would require me to write a 'if' statement for everything I want to check- the end application that I'm thinking of using this in is going to use around 50 such keywords. That's a lot of 'if' statements to write and I was hoping for a much smaller section of code. You missed my point. I was thinking you were only expecting one smiley to be in the message from the listen, and that it would be at the end, at which point you would want to look for only the last segment of the list. Or if it were expected to be in the front of the message, then the first segment. Newgate Ludd's function does look appropriate, in that after you use the llParseString2List function to seperate each word into it's own element, you could use a for loop to check each word against the filter list.
|
|
Lexi Foley
Registered User
Join date: 1 Mar 2006
Posts: 43
|
This works like you want i guese but hasnt got much to do whit lists
09-29-2006 07:00
default { state_entry() { llListen(0,"",llGetOwner(),""); } listen(integer channel,string name,key id,string message) { message=llToLower(message); list filter1=[":d",">:)",":)",":(",":'(",";)",":p"]; //note >:) before :) the search starts from the beginning of the list otherwise it will find :) first string say="You used the smiley ' "; @other; integer i; for(i=0;i<llGetListLength(filter1);i++) { string filterstring=llList2String(filter1,i); integer substring=llSubStringIndex(message,filterstring); if(substring != -1) { llSay(0,say+filterstring+" '"); message=llDeleteSubString(message,substring,substring+llStringLength(filterstring) - 1); say="And smiley ' "; jump other; } } } }
|
|
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
|
09-29-2006 10:00
Scratch everything I just said **edited out** next time i'll pay more attention before I post a reply.
|
|
Don Misfit
Registered User
Join date: 1 Jun 2006
Posts: 60
|
09-29-2006 14:31
When using llListFindList() with 2 lists, it searches for a matching *sequence*, not a "one of" ... So: list lstA = [ "a", "b", "c", "d", "e" ] ; list lstB = [ "b", "c" ] ; list lstC = [ "b", "c", "d" ] ; list lstD = [ "b", "d" ] ; p = llListFundList ( lstA, lstB ) ; // p == 1 (start of matching sequence) p = llListFundList ( lstA, lstC ) ; // p == 1 (again, start of matching sequence) p = llListFundList ( lstA, lstD ) ; // p == -1 ("b,d" is not found in "a,b,c,d,e")
Hope that helps clear it up... Don
|