Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Question About Scanning Text

Zuzi Martinez
goth dachshund
Join date: 4 Sep 2004
Posts: 1,860
10-31-2004 21:21
i'm looking at a project that will need to listen for different key words and respond appropriately. i want to do it nice and efficiently and not use more sim resources than necessary but i haven't done anything like this yet. can i get some tips on ways to scan text efficiently and things to avoid if they're too much work for the sim? i don't want someone to do it for me or drop a big "here's how it's done" script on me, just advice like "don't use this function cause it's a hog, use that one" and such.

and no, it's not to spy on people or do anything that breaks the TOS so don't worry.

edit: to be clearer, it's not just a listen and a couple commands in an if/else. it's going to check everything that is said around it against a big fat list of words and phrases.
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
10-31-2004 21:56
If i'm reading you correctly, you have a list of predetermined words that you would like to check against every time someone talks within the vicinity of the object... and then have your object respond if a key word matches up with the list?

you could use a function to check against the list of words, and have it return true or false... something like:

CODE
//----Global Varables-----//
list gKeyWords = ["word", "water", "wee"]; //make these words lowercase

//----Functions----//
func_init(){
llListen( 0, "", "", "" ); // change this to how you want to listen... this is set to listen to everyone on 0 chat channel
}

integer func_check( string word ){
integer i = 0;
integer listLength = llGetListLength( gKeyWords ); //This would get your lists length
for( i = 0, i < listLength ; i++ ){
if( llList2String( gKeyWords, i ) == word ){ //We loop through and check each word in the list against the word
return TRUE; // If a check is matched, stop the function and return it TRUE
}
}
return FALSE; // no check was found so return FALSE
}

//----Onto the Default state----//
default(){
state_entry(){
func_init(); //Fire the initial function to listen upon entry
}

on_rez( integer t ){
func_init(); //Fire the inital function to listen when rezzed
}

listen( integer c, string n, key id, string m){
m = llToLower( m ); //first change all strings to lower that are heard on the chat channel
if ( func_check( m ) ){
//Do some code here, because we had a word match
}else{
//Do some code here, if you want... but no match has been found.
}
}
}


if this raises a syntax error, i appologize.... i'm just kinda doing it out of memory.
I hope i'm not 'doing it for you'... rather showing you 'how i would go about doing it' and just offering a function that you could use. Hope this helps!

Also note that this would only check for "one word" strings. So if someone typed "Water wee" this would return false. Are you looking for checking for a key-word in a string of words? For instance... if i were to say in chat "Water likes to run".... and you would like to check if the word run exists in the string?

--Water
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-31-2004 22:33
Time flies like an arrow but fruit flies like a banana.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Zuzi Martinez
goth dachshund
Join date: 4 Sep 2004
Posts: 1,860
10-31-2004 23:09
yeah you read me right for what i want to do Water. i *think* what you wrote works if people say one word at a time? like that thing about if they say "Water wee" it returns false is because it's two words not because one of the words they said isn't in the list right?

i'm wanting to check every word that's said so i'm guessing i need to capture everything someone says, convert it to a list of words, and check every word in that list against every word in my list? that's why i was asking if it's a big resource hog because that sounds like alot of work for the server. like if they say 10 words and i have 10 words in my list that's 100 individual checks for that one time. and i want more than 10 words in my list hehe. if it's not a big deal that's cool but i dunno yet.
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
11-01-2004 02:20
Well if you did it manually, it could take up some time. But there might be a built in function that could do your work for you. Such as find sub list, or llString2List( string, filter list, break list). if you broke the string up using a filter list of [] and a break list of (list)" ". And then used the command again with a filter list of 'magic words', and a break list of (list)" ". Then you could get the length of both lists. the difference between the two lists would be the number of magic word used in the string.

But then the script wouldn't know witch magic words were used, or how many times the same magic words were used. But if you filtered the string with a few different lists, you could have a ruff pull of how many 'happy', 'sad', 'nutral' words were used.
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
11-01-2004 02:24
CODE

list listtocheck = llParseString2List( sInString, [" "], [] );
_____________________
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
11-01-2004 02:34
Azelda's got what i was getting at for checking mutliple words in a string. It's not as intensive on the server as you might think... i have tons of scripts that specialize in string and list parsing/sorting/extracting/manipulation etc. The way azelda puts it, is basically creating a dynamic list of words into a list seperating them by a space. Just take that idea with mine, by having it check that dynamically created list against the list you have. Be careful here though, because if it DOES it get too lengthy you will run into stack-heap collision errors, and try to find work arounds for it. At this point it's all just fun experimentation for you now :)

--Water
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Zuzi Martinez
goth dachshund
Join date: 4 Sep 2004
Posts: 1,860
11-01-2004 10:28
sweet. thanks guys.
Lit Noir
Arrant Knave
Join date: 3 Jan 2004
Posts: 260
11-01-2004 10:39
Okay, Wiki's down so I can't check this, but what about llListFindList? Parse the string to a list like you have, then use ListFindList. If there are no matches, you get a -1, otherwise I believe it returns the list element index for the first one found. I've used this a number of times when searching for one word, so I'm not sure how well it scales to more key words if at all. Not sure if this is more sim efiicient than the above method. This method is worthless if you need to know which ones or their exact locations (course you could iterate ListFindList for each key word).
Zuzi Martinez
goth dachshund
Join date: 4 Sep 2004
Posts: 1,860
11-01-2004 11:31
Lit, off the subject but the wiki moved until whatever problem it's having gets fixed. here's the new addy...

http://www.badgeometry.com/disabled/HomePage

thanks for the suggestion about llListFindList. i think i'll probably end up using that sometime.