Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Listen - replace - cant make sentences?

Thili Playfair
Registered User
Join date: 18 Aug 2004
Posts: 2,417
07-10-2006 06:19
Got some idea but not to sure SL can do it, tried gestures wont work as it only picks up the first word and then blarg rest.

So tried a listen to change a word to something else, 1 word work, but trying to make a sentence and SL wont do it.

So what am i trying to do?, have a script to change words said to something else

exsample
I am bored
would become >
jeg kjeder meg

this is just some idea for another idea i have, but cant get it to work with several words, just , SL limitations? or whatnot, not to sure how to script this, if / else if
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
07-10-2006 08:09
Easiest way would maybe be to have a list of words and their replacements in pairs (or two separate lists perhaps). And then take an incoming message and break it into individual words around the spaces, full stops and so-on.

For example:

CODE
list searches = ["carrot", "banana", "apple"];
list replaces = ["cake", "split", "pie"];

string strReplace(string str, string search, string replace) {
integer x; integer l = llStringLength(search) - 1;
@loop;
x = llSubStringIndex(str, search);
if (x >= 0) {
str = llDeleteSubString(str, x, x + l);
str = llInsertString(str, x, replace);
jump loop;
}
return str;
}

default {
state_entry() {
llListen(1234, "", llGetOwner(), "");
}
listen(integer x, string name, key id, string msg) {
x = llGetListLength(searches);
msg = llToLower(msg);
@loop;
if ((--x) >= 0) {
msg = strReplace(msg, llList2String(searches, x), llList2String(replaces, x));
jump loop;
}
llSay(0, msg);
}
}
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Thili Playfair
Registered User
Join date: 18 Aug 2004
Posts: 2,417
07-10-2006 09:44
\o thanks that was something i was looking at tollList2String , but make no sense for me <.<

Works with text alright :p trouble is i want to try make .wavs to play in order not really text , text was just a trigger to that and that .wav :o

erk dunno i have no idea how to make this either, your script made me get some new stuff i never done tho , only way i learn is to read others :p not to good with reading page after page of text on wiki , trying tho.

hello im bored
"wav1" "wav2" "wav3" ...prob delay itself <.< so prob blarg :O i have no idea , odditiy ideas \o/

Dah nm think i got it -.o, well for one sound then i need kind of a delay to next cause triggering several never work :q
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
07-10-2006 12:01
ah, hrm, in that case what you want it simpler, you just want to take the words, break them apart and see what they are (I'll also use less complicated looking loops, I use jump in my own stuff normally so I forget =):

CODE
list searches = ["carrot", "banana", "apple"];
// Put the names of your sounds (if they're in the object's inventory)
// or the UUIDs for each sound in this list:
list sounds = ["cake.wav", "split.wav", "pie.wav"];

default {
state_entry() {
llListen(1234, "", llGetOwner(), "");
llSetSoundQueueing(TRUE); // Makes this a little more robust
}
listen(integer x, string name, key id, string msg) {
msg = llToLower(msg); // Put to lower case
list words = llParseString2List(msg, [" ", ".", ","], []);
integer i; // For the loop to use as a counter:
for (i = 0; i < llGetListLength(words); ++i) {
msg = llList2String(words, i); // Get the current word
x = llListFindList(searches, [msg]); // Is it a key-word?
if (x >= 0) { // If it is then play a sound!
llPlaySound(llList2String(sounds, x), 1.0);
// Some delay, depends on the length of your sounds:
llSleep(1.0); // Wait one second
}
}
}
}
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)