Jump to content
MIVIMEX

loop single sound script with volume control

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...