Reymundo Posted August 31, 2016 Share Posted August 31, 2016 So I see this script http://wiki.secondlife.com/wiki/Script:Random_Sounds That seems to pick a random sound file from the item's inventory but is it possible for it to do that sound file at a random time interval? Trying to make something that plays different baby sound effects at random time intervals. Link to comment Share on other sites More sharing options...
Rolig Loon Posted August 31, 2016 Share Posted August 31, 2016 It already does that. That's what the line that says llSetTimerEvent( MinimumSeconds + (llFrand( MaximumSeconds - MinimumSeconds)) ); does. Link to comment Share on other sites More sharing options...
Reymundo Posted August 31, 2016 Author Share Posted August 31, 2016 So basically I could put say 10 sounds in there and it will pick one randomly at a random interval and play it? Link to comment Share on other sites More sharing options...
Rolig Loon Posted August 31, 2016 Share Posted August 31, 2016 Precisely. As written, at random intervals of 10 to 30 seconds. Mess with the timing yourself to change the interval. Link to comment Share on other sites More sharing options...
Reymundo Posted August 31, 2016 Author Share Posted August 31, 2016 Okay only problem is when I pull it into SL, it oranges out the whole thing... Link to comment Share on other sites More sharing options...
Rolig Loon Posted September 1, 2016 Share Posted September 1, 2016 It does what?? :smileyvery-happy: Link to comment Share on other sites More sharing options...
Madelaine McMasters Posted September 1, 2016 Share Posted September 1, 2016 I was initially as confused as Rolig, but I have a theory. The LSL editor highlights type-definitions in orange, and maybe it got confused and painted your entire script that color. Or it thought the entire script was a string and printed in red. I'm guessing you copied and pasted the entire example web page into the script window, which won't work. Here's the script, cleaned up... float MinimumSeconds = 10.0; // Minimum time between successive sounds (seconds)float MaximumSeconds = 30.0; // Maximum time between successive sounds (seconds)float volume = 0.5; // How loud? Between 0 and 1.integer sounds = 0; // # sounds in inventorylist soundnames;LoadSounds() { soundnames = []; sounds = llGetInventoryNumber( INVENTORY_SOUND ); integer n; for ( n=0; n < sounds; ++n ) { soundnames += llGetInventoryName( INVENTORY_SOUND, n ); }} default { state_entry() { LoadSounds(); if ( sounds > 0 ) llSetTimerEvent( 0.1 ); else llOwnerSay("No sounds."); } timer() { integer random = (integer) llFrand ( sounds ); string sound = llList2String( soundnames, random ); llTriggerSound( sound, volume ); llSetTimerEvent( MinimumSeconds + (llFrand( MaximumSeconds - MinimumSeconds)) ); } changed (integer change) { if (change & CHANGED_INVENTORY) { llResetScript(); } }} If that's not what you meant, I remain as confused as Rolig. Link to comment Share on other sites More sharing options...
Rolig Loon Posted September 1, 2016 Share Posted September 1, 2016 Madelaine McMasters wrote: [ .... ] If that's not what you meant, I remain as confused as Rolig. That's hard to imagine, but possible. Link to comment Share on other sites More sharing options...
Madelaine McMasters Posted September 1, 2016 Share Posted September 1, 2016 Rolig Loon wrote: Madelaine McMasters wrote: [ .... ] If that's not what you meant, I remain as confused as Rolig. That's hard to imagine, but possible. Don't overestimate me! Link to comment Share on other sites More sharing options...
Reymundo Posted September 1, 2016 Author Share Posted September 1, 2016 Yes I had copy and pasted from the website and wasn't sure how to 'clean it up' as you put it. But seems like it works, the only confusing part is the intervals...is that after the first sound plays or after the sound file finishes? Link to comment Share on other sites More sharing options...
Rolig Loon Posted September 1, 2016 Share Posted September 1, 2016 Look at the timer event. When it is triggered, the script chooses a sound and playes it, then calculates the random time for triggereing the timer event next time. It's exactly what you would expect a timer event to do: trigger, do something, wait, trigger, do something else, wait, wash, rinse, repeat .... Link to comment Share on other sites More sharing options...
Reymundo Posted September 1, 2016 Author Share Posted September 1, 2016 I asked as it seemed like it was back to back and not 10 seconds after the sound had finished. But thank you. Link to comment Share on other sites More sharing options...
Rolig Loon Posted September 1, 2016 Share Posted September 1, 2016 Well, if you play a sound that takes a full 10 seconds to play, then yes, the next one might be triggered almost immediately after the first one ends. The timer event has no idea how long your sound files are. All it's doing is starting one when you tell it to. That's what timer events do. If you are really using long files, I'd suggest monkeying with the minimum and maximum times to create more space between them. Link to comment Share on other sites More sharing options...
Recommended Posts
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