Jump to content

loop single sound script with volume control


MIVIMEX
 Share

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

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

Recommended Posts

Hello! Please help to create loop single sound script with volume control via pop-up menu. So far I managed to create this script, but maybe there is the way to simplify it? I will be grateful for any help! Thank you!


list MENU_MAIN = ["100%VOL", "50%VOL" , "25%VOL" , "OFF"]; //up to 12 in list
string sound = "a78fd32e-0179-437b-9a39-6b24916aa433";
integer menu_handler;
integer menu_channel;
menu(key user,string title,list buttons)
{
    llListenRemove(menu_handler); //BugFix 5/2008
    menu_channel = (integer)(llFrand(99999.0) * -1);
    menu_handler = llListen(menu_channel,"","","");
    llDialog(user,title,buttons,menu_channel);
    llSetTimerEvent(30.0); //how long to wait for user to press a button before giving up and closing listen
}

default
{
    state_entry()
    {
        //nada
    }

    touch_start(integer total_number)
    {
        menu(llDetectedKey(0), "\nText for Menu.", MENU_MAIN);
    }
    
    listen(integer channel,string name,key id,string message)
    {
        if (channel == menu_channel) 
        {
            llListenRemove(menu_handler); //close listen
            llSetTimerEvent(0); //stop timeout timer
            if (message == "100%VOL")
            {
                llStopSound();
                llLoopSound(sound, 1.0);
            }
            else if (message == "50%VOL")
            {
                llStopSound();
                llLoopSound(sound, 0.5);
            }
            else if (message == "25%VOL")
            {
                llStopSound();
                llLoopSound(sound, 0.25);
            }
            else if (message == "OFF")
            {
                llStopSound();
            }
            //else if (message == "Button")
            //{
                //do something
            //}
        }
    }
    
    timer() //VERY IMPORTANT menu timeout
    {
        llListenRemove(menu_handler); //close listen
        llSetTimerEvent(0); //stop timeout timer
    }
}

 

Edited by MIVIMEX
Link to comment
Share on other sites

One way would be to use numbers only in the buttons and set OFF = 0 and check the value returned and either use the value direct or within a range of values. This would eliminate all 4 string checks and only require a simple value check to tell if llStopSound() XOR llLoopSound().

 

 

 

Edited by Rachel1206
Spell error
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Wulfie Reanimator said:

llAdjustSoundVolume is a thing for llPlaySound and llLoopSound.

Yes.  The OP's method will work too, as long as he continues to use llStopSound and then start a new llLoopSound.  As the note in the wiki for llLoopSound says

  • If a second call to loop the same sound at a different volume is made from within the same script NO volume change is made.
  • llStopSound set just previous to the second call for a new volume allows the volume change with no discernible pause.

That has the minor advantage of avoiding the 0.1 second delay inherent in llAdjustSoundVolume, not that it's much of a concern. ;)

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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