Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help me understand this sound script

ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
03-14-2008 10:03
I want to edit this script that came from a freebie talking parrot to randomly play other sounds. It appears that state_entry sets the timer to play "Uh-huh Male" every 40 to 60 seconds. And each timer event resets the timer to 40 to 60 seconds.

I'm uncertain exactly what is happening in the touch_start event, it appears that when touched it will rotate between the other 5 sounds every 1 to 5 seconds. Am I correct in this?

CODE


default
{
state_entry()
{
//llSay(0, "JeanPaul's Parrot!");
llSetTimerEvent(llFrand(40)+20);
}

touch_start(integer total_number)
{
float mynote;
mynote = llFrand(5);
mynote = (integer)mynote;

//llSay(0, (string)mynote);

if (mynote == 0) {
llTriggerSound("Kiss 1", 0.5);
} else if (mynote == 1) {
llTriggerSound("Wolf Whistle", 0.5);
} else if (mynote == 2) {
llTriggerSound("Whistle call", 0.5);
} else if (mynote == 3) {
llTriggerSound("Kiss 1", 0.5);
} else if (mynote == 4) {
llTriggerSound("Whistle call", 0.5);
}

}

timer()
{
llTriggerSound("Uh-huh Male", 0.5);
llSetTimerEvent(llFrand(40)+20);

}



}
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
03-14-2008 10:11
No, actually the state_entry sets the sound to play every 20 seconds plus a random amount of seconds between (0 - 40)

llFrand is a random function that returns a number between 0 and the number you put in.
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
03-14-2008 10:14
CODE

default
{
state_entry()
{
//llSay(0, "JeanPaul's Parrot!");
llSetTimerEvent(llFrand(40)+20); // random time between 40-60 seconds
}

touch_start(integer total_number) // randomly will play one of those sounds each time you touch it
{
float mynote;
mynote = llFrand(5);
mynote = (integer)mynote;

//llSay(0, (string)mynote);

if (mynote == 0) {
llTriggerSound("Kiss 1", 0.5);
} else if (mynote == 1) {
llTriggerSound("Wolf Whistle", 0.5);
} else if (mynote == 2) {
llTriggerSound("Whistle call", 0.5);
} else if (mynote == 3) {
llTriggerSound("Kiss 1", 0.5);
} else if (mynote == 4) {
llTriggerSound("Whistle call", 0.5);
}

}

timer() // play that sound every 40-60 seconds
{
llTriggerSound("Uh-huh Male", 0.5);
llSetTimerEvent(llFrand(40)+20); // resets the 40-60 second random timer

}



}
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
03-14-2008 10:16
The touch_start causes it to pick one of five sounds and play it once.
_____________________
So many monkeys, so little Shakespeare.
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
03-14-2008 10:35
http://lslwiki.net/lslwiki/wakka.php?wakka=llFrand

llFrand(40) will return a number between 0 and 40.

so:

llSetTimerEvent(llFrand(40)+20); // random time from 0 to 40 plus 20
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-14-2008 16:32
if you move the code from touch start to a function, and call the function from touch start AND the timer event, it will play the sounds randomly every [20-60) seconds or on touch....

it might also be simpler to have it call trigger in only one place, instead of each if, by placing the sound names in a list, randomizing the list before playing, and then just play the first listed one like so

CODE

list gLstSounds = ["Kiss 1", "Wolf Whistle", "Whistle call", "Kiss 1", "Uh-huh Male"];

fPlayRandom(){
llTriggerSound( llList2String( llListRandomize( gLstSounds, 1 ), 0 ), 0.5);
}


using list randomize inside of the list 2 string saves reording the actual list, so you can still call specific sounds by their index, and with this method you don't need to know the amount of sounds in the list.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
03-19-2008 19:24
Thank you to everyone who responded. I understand LLFrand much better now and I'm trying out the other ideas suggested. I will post any final examples I come up with TY again :)
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
03-20-2008 07:54
Also you can play random sounds without putting them in a list:

float soundAmount = (float)(llGetInventoryNumber(INVENTORY_SOUND)-1);

And then

llTriggerSound(llGetInventoryName(INVENTORY_SOUND,llFrand(soundAmount)));
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
03-29-2008 14:17
Here is the script I ended up with, works great.

Void, thank you for the tip:
From: someone
if you move the code from touch start to a function, and call the function from touch start AND the timer event, it will play the sounds randomly every [20-60) seconds or on touch....


It took me a few moments to understand what you were saying, essentially creating a function. I'd seen particles called that way, but didn't understand it, that is a great new tool I've now added to my LSL kit of parts. :)

CODE

//Script ramdomly selects a sound and plays it every 60-80 seconds

list gLstSounds = ["UUID 1","UUID 2", "ETC."]; // this is a list of the sound UUID's

fPlayRandom()
{
llTriggerSound( llList2String( llListRandomize( gLstSounds, 1 ), 0 ), 1.0);
}// llTriggerSound call placed inside of a function which
//can be called by the touch even or the timer.
//This randomly picks one of the sounds from the list to play.

default
{
state_entry()
{
fPlayRandom(); // calls for the function to run
llSetTimerEvent(llFrand(60)+20); // sets time for timer() below, random time between 60-80 seconds
}

touch_start(integer total_number) // randomly will play one of those sounds each time you touch it
{
fPlayRandom();// calls for the function to run
}

timer() //plays as frequently as dictated by the llSetTimer call in state_entry

{
fPlayRandom();// calls for the function to run
}

}

_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
03-29-2008 14:23
From: Kahiro Watanabe
Also you can play random sounds without putting them in a list:

float soundAmount = (float)(llGetInventoryNumber(INVENTORY_SOUND)-1);

And then

llTriggerSound(llGetInventoryName(INVENTORY_SOUND,llFrand(soundAmount)));


Kahiro, Thanks, that is a good idea too, I decided against using it only because I wanted to use UUID's instead of having sound files in the inventory.
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo