Jump to content

Shuffle or randomize which sound will play?


maeglutz
 Share

Recommended Posts

Hello ^^ I'm working on a typer and I'd like for the sounds to be randomized, so that it's not the same one everytime. Unfortunately, I don't understand how to put in multiple, let alone make them shuffle.

 

default
{
    state_entry()
    {
       llSetTimerEvent(1);
    }
  
timer() {
                    if (llGetAgentInfo(llGetOwner()) & AGENT_TYPING) 
       
                    {
                 llLoopSound("Typie", 0.2);  
                    }
              
                else 
               {
                llStopSound();
                 }
        }
}

 Here's what I have so far ^^

Link to comment
Share on other sites

first , get all your sounds in a list in state entry.

 next count the items in your list of sounds and choose a random numbered one to play.

 

list sounds;
default
{
    state_entry()
    {   integer count;
        string name;
        while ( (name = llGetInventoryName(INVENTORY_SOUND, count))  )
        { sounds += name;
          ++count;   
        }
         llSetTimerEvent(0.2);
    }
   timer()
   { integer len = llGetListLength(sounds) - 1;
     if (llGetAgentInfo(llGetOwner()) & AGENT_TYPING)
     {   integer place = llRound(  llFrand(len)    );
         llLoopSound( llGetInventoryName(INVENTORY_SOUND, place), 0.2);  
       
     }              
      else
     {   llStopSound();
     }
   }
}

 

Link to comment
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.

 Share

×
×
  • Create New...