Jump to content

On/off sound script


Lyrixier
 Share

You are about to reply to a thread that has been inactive for 3591 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello, I am just now getting more into scripting of second life, and I usually look at other scripts for help (since I don't much) and I'm trying to create a script that when clicked, it toggles the entire chain of sounds to turn completely off. I also need help with the linking of the sounds because I don't know any other way to do it. Please help!

integer toggle;
string sound;
default
{
state_entry()
{
sound = llGetInventoryName(INVENTORY_SOUND,0);
}

touch_start(integer total_number)
{
llSay(0, "PARTY ROCK");
llSetPrimitiveParams([
PRIM_GLOW,ALL_SIDES,0.20]);
}
llSay(0, "Every day I'm shufflin'.");

llPlaySound(llGetInventoryName(INVENTORY_SOUND,12),1);
llSleep(10.0);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,2),1);
llSleep(10.0);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,3),1);
llSleep(9.9);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,4),1);
llSleep(9.9);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,5),1);
llSleep(9.9);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,6),1);
llSleep(9.9);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,7),1);
llSleep(9.9);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,8),1);
llSleep(9.9);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,9),1);
llSleep(9.9);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,10),1);
llSleep(9.9);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,11),1);
llSleep(9.7);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,1),1);
llSleep(9.9);
llPlaySound(llGetInventoryName(INVENTORY_SOUND,0),1);
}

touch_start(integer total_number)
{
toggle=!toggle;
if(toggle){
llLoopSound(sound,1.0);
}
else{
llStopSound();
}
}
}

It doesn't work so please respond if you know the problem!

 

Link to comment
Share on other sites

llPlaySound() can only have one sound playing from a prim at one time.  Each of those will cause the prior call to stop playing.  llSleep() stops the script from responding to any touches (it basically pauses the script completely.)  I'm assuming your sleep calls are pausing for the duration of the sound file, so this might not be a problem.

llTriggerSound() will allow you to play more than one at the same time, but they do not follow the prim around, the sound plays from the location at which it was started.

 

It looks like you are trying to play these in sequence?  If so, and you want it to respond during the playing, you'll need a timer even to 'switch out' sounds.  The sleeps in the first touch event keep it from responding to touches to turn it off except in the very brief interval when it starts the next sound.

 

In a psuedo-code style, this would look like:

 

Get list of sounds to play and their durations into lists (sounds and durations), set 'playing' to false, and your sound number 'index' to 0.

Set timer to very small value.

On Touch, toggle a flag variable 'playing' and if it is false, turn Timer off.

In Timer, Play sound 'index', and change timer duration to duration 'index', and increment 'index', and check if index is past the end of the list, if so, set it back to 0.

 

 

Link to comment
Share on other sites

I'm still very confused on how to do it. I get a little on what you're saying, but I don't know how to combine the sounds and have them to where they turn on/off because when I try to do it, it doesn't stop the sounds and it keeps on going. Or when I try to add in sounds, it says that I'm only able to add 1 sound.

Link to comment
Share on other sites

You shouldn't be using llLoopSound, if your modified script is still doing that.  Your timer should simply be triggering each new sound bite (with llPlaySound) as the previous one ends.  There are only a few things to be aware of:

1. An avatar has to have any sound preloaded before s/he can hear it played in world.  So, you need to design your system to preload each sound bite while the previous one is playing.

2. Unless you plan on changing the duration of the timer event for each separate sound bite (which is a real pain), it's best if all of the sounds bites are exactly the same length. 

3. There is no way to stop a sound that is already playing.  Once it is triggered, it will play to the end.  You can of course prevent the next sound bite from playing.

You can write a bare bones timer event that looks like this...

timer(){    llPlaySound(llGetInventoryName(INVENTORY_SOUND, gCount), 1.0);    ++gCount;    // Global counter integer, set to = 0 in your touch_start event    if (gCount <= llGetInventoryNumber(INVENTORY_SOUND) )    {        llPreloadSound(llGetInventoryName(INVENTORY_SOUND, gCount), 1.0);    }    else    {        llSetTimerEvent(0.0);  // All sounds have been played.  Stop.    }}

 Just write your touch_start event like a standard toggle switch that plays the very first sound file,  turns the timer on and off, and resets gCount to = 0 when it's ON. Preload that first sound in state_entry. Then add whatever bells and whistles you need for making it pretty.

 

   

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3591 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...