Jump to content

How to Loop a sound in a prim attached to my avatar


SweetLilMsMissy
 Share

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

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

Recommended Posts

I've never written a script or have any experience writing one but i thought it would be fun to create my own hud of sound clips with my voice. I did manage to find a basic script that will loop a sound upon touch but it will not play in world. I've tried llPlaySound & LoopSound Scripts but only i can hear the sounds when the hud is attached to my avatar.

I also found a llTriggerSound script that can trigger the sound when i touch but I need it to loop the sound as well and turn off by touch as wel. Can anyone direct me to a script that will trigger the sound in world & toggle the loop off/on when touched or help me combine a loop script with the one i have pls? The script below very basic & i don't really understand scripting but I found it by lucky accident. 

 

default
{
     touch_start(integer total_number)
    {
    llTriggerSound("sound", 1.0);
     }
 
}

 

Edited by SweetLilMsMissy
Link to comment
Share on other sites

Quite right.  As it says in the LSL wiki notes about llLoopSound:

  • When call made from HUD attachment sound is only heard by agent the task is attached to.

So, llLoopSound is designed to work the same way that llPlaySound is. That is, the sound played in an attachment is heard only by the person wearing it.  llTriggerSound is designed to by audible to other people.  There's really no easy way to loop llTriggerSound, although you could always run it repeatedly in a timer event.  The main trick there would be to run the timer for exactly the length of the sound clip so that there's no gap or overlap each time it is re-triggered. Especially if your sound is patched together from several clips ( as a song, for example ), that could be not only challenging but disappointing.

".

  • Like 1
Link to comment
Share on other sites

Well, as I said, it will be tricky to get the timing right -- easier if you made the sound yourself, so you know exactly how long you made it in your sound editor -- but very simply:

integer iON;

default
{
     touch_start(integer num)
     {
          llSetTimerEvent(length_of_my_sound_clip * ( iON = !iON ) );  // Turn the timer on with a toggle switch
          llTriggerSound( my_sound_clip,1.0);   // Play it one time here
     }

     timer()
     {
          llTriggerSound( my_sound_clip,1.0);   // Play it over and over and over and over ...
     }
}

As always, scripts and code snippets posted in this forum are not guaranteed to be perfect, or to even work.  They are offered purely as examples.            

Edited by Rolig Loon
Link to comment
Share on other sites

13 minutes ago, SweetLilMsMissy said:

Interesting, I understood more than i thought. Nice! Well i can surely give the timer a try. Any ideas how to add the timer element to the script i have?

Rollig has already done it as i posted.

Edited by steph Arnott
cleared the post
Link to comment
Share on other sites

Ok, ty so much. I just tried it, seems to double the sound replay when i use the exact seconds from the clip but 10 sec works. I toggle it on and it play until i touch it again, then it goes off after it play last time.

I guess that is as close to toggle off/on or loop as i will get. Thank you so much for your help!

 

Link to comment
Share on other sites

Oh, yes, since you said you wanted it to loop, that's what you got.  Once you trigger a sound in LSL, it plays all the way to the end.  You can't interrupt it.  So, clicking my little demo  script one time will play the sound instantly and will start the timer.  When the timer triggers ten seconds later, the sound will play again.  It will continue looping until you click again, because that kills the timer.

So, if you only want to play the sound one time instead of looping, click it the second time before the timer triggers. That will toggle the timer off so that the sound never plays for the second and subsequent times.

I suggest taking a simple script like this apart and tinkering with it until you understand exactly how it works.  Rewrite it yourself to make it do something slightly different and to prove to yourself that you understand. Even something as short as this contains several logical elements that deserve careful study.

Edited by Rolig Loon
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1862 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...