Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

My first voice script

a lost user
Join date: ?
Posts: ?
08-30-2005 07:05
I adapted it from a couple of other scripts. Mostly from Imani Moseley's Texture Change on Voice Command Script. I was able to understand Imani's logic. Thanks Imani for the push. :-)

My script is very simple. It is only supposed to whisper back a random phrase (when the random command is given) or chant a couple of phrases (when the chant command is given). I figure if I can get this to work, I can use it as a base to write other voice commanded and random scripts.

But guess what? It don't work. :-)

Please help. One question I have is how do I make it so anyone can talk to it and make it whisper?

CODE

// channel 111
// commands: start, random, chant, faster, slower, stop

//this will make it respond to My voice, but I'd rather have it respond to everyone, and I'm not sure how to do that.
key owner;

//the temp value of the command
integer listen_handle;

//time between chants or phrases
float chantdelay = 5.0;

//ranges of phrase use
integer usephraselow;

integer usephrasehigh;

float nowphrase;

list phraselist = ["phrase zero","phrase one","phrase two","phrase three","phrase four","phrase five","phrase six","phrase seven","phrase eight","phrase nine","phrase ten","phrase eleven","phrase twelve","phrase thirteen"];

whisperwords()
{
//if the chant command is used, there are only two chants to interchange between
if (usephrasehigh < 3)
{
if (nowphrase = 1)
{
llWhisper(0,"repeat this phrase");
nowphrase = 2;
}
else
{
llWhisper(0,"repeat that phrase");
nowphrase = 1;
}
}
else
{
nowphrase = llFrand(usephrasehigh - usephraselow)+ usephraselow;
list randlist = llListRandomize(phraselist,1);
llWhisper(0, llList2CSV(randlist));
}
}
default
{
state_entry()
{
nowphrase = 0;
usephrasehigh = 0;
llListenRemove(listen_handle);
owner=llGetOwner();
listen_handle = llListen(111,"",owner,"");
}

timer()
{
whisperwords();
}

listen(integer channel, string name, key id, string message)
{
if (message == "chant")
{
nowphrase = 1;
usephrasehigh = 0;
}
else if (message == "random")
{
usephraselow = 0;
usephrasehigh = 13;
}
else if (message == "start")
{
llSetTimerEvent(chantdelay);
}
else if (message == "stop")
{
llSetTimerEvent(0);
}

else if (message == "faster")
{
chantdelay /= 2.0;
if (chantdelay < 0.25)
chantdelay = 0.25;
}
else if (message == "slower")
{
chantdelay *= 2.0;
}

}
}


Thanks for the help
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
08-30-2005 08:27
change the line:

CODE
listen_handle=llListen(111, "", owner, '');

to:
CODE
listen_handle=llListen(111, "", "", "");


The parts of the command in brackets define in turn the channel on which you listen, the name of the 'speaker' (can be an object or a person) that will be listened to, the key of the speaker that will be listened to, and finally the message that will be listened for. So the first line ignores anyone that isn't you because they don't speak with your key. You MUST supply a channel number. Blanks "" or NULL_KEY in the other slots mean that anyone or thing can be heard there.

Some people will suggest you should use:
CODE
listen_handle=llListen(111, "", NULL_KEY, "");

But for this function they're the same.
a lost user
Join date: ?
Posts: ?
08-30-2005 09:11
That explains how anyone can use the item very well. Thank you. :-)

But the voices are still not whispering..... :-(
a lost user
Join date: ?
Posts: ?
Fix Your If Statements
08-30-2005 10:11
I believe the problem is in your conditional statements below:

CODE
 
if (nowphrase = 1)
{
llWhisper(0,"repeat this phrase");
nowphrase = 2;
}
else
{
llWhisper(0,"repeat that phrase");
nowphrase = 1;
}


You are using the assignment operater ("=";) and not the test for equality conditional operator ("==";).
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
08-30-2005 10:17
try
CODE
integer nowphrase;

in the declarations part, before default
and
CODE
nowphrase = llFloor(llFrand(usephrasehigh - usephraselow)+ usephraselow);
llWhisper(0, llList2String(phraselist, nowphrase));

in the whisper words function.

I'm also not clear what the chant section is trying to do. It ought to whisper cyclically "Repeat this phrase" and "Repeat that phrase" and nothing else, that's what it's written to do anyway.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
08-30-2005 10:19
And yes, good catch on the if = not if ==
a lost user
Join date: ?
Posts: ?
08-30-2005 10:24
Thanks everyone.

From: someone

I'm also not clear what the chant section is trying to do. It ought to whisper cyclically "Repeat this phrase" and "Repeat that phrase" and nothing else, that's what it's written to do anyway.


That's right. There's supposed to be two modes: chant (which is the one described above) and random which will pick on phrase from the list and say it at every timer event). Saying /111 chant or /111 random will change the mode. I hope. :-)