|
Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
|
10-24-2006 12:33
I chopped up and pasted a few scripts together to make a touch to turn on/off sounds in an item that would randomly play a sound from the inv but it only plays a random sound once and won't continue to randomly play the other sounds. Can someone help? integer group = FALSE; integer anyone = FALSE; integer on = FALSE; float min_delay = 30; // min seconds between sounds float max_delay = 30; // max seconds between sounds float sound_level = 1.0; // volume level between 0.0 & 1.0
integer allowed( key lid ) { if ( lid == llGetOwner() ) {return TRUE;} if ( group ) { if ( llSameGroup( lid ) ) {return TRUE;} } if ( anyone ) {return TRUE;} return FALSE; }
init() { group = FALSE; anyone = FALSE; if ( llGetInventoryType( "allow_group" ) == INVENTORY_NOTECARD ) { group = TRUE; } if ( llGetInventoryType( "allow_anyone" ) == INVENTORY_NOTECARD ) { anyone = TRUE; } llStopSound(); on = FALSE; } default { state_entry() { init(); } on_rez( integer r ) { init(); } changed( integer c ) { if ( c & CHANGED_OWNER ) { llResetScript(); } } touch_start( integer t ) { if ( allowed( llDetectedKey(0) )) { if ( on ) { on = FALSE; llWhisper(0, "Sounds Off"); llStopSound(); } else { on = TRUE; llWhisper(0, "Sounds On"); llSetTimerEvent(1.0);//not sure if the timer in this is working right integer num_sounds = llGetInventoryNumber(INVENTORY_SOUND); integer i = llFloor(llFrand(num_sounds)); string sound = llGetInventoryName(INVENTORY_SOUND, i); llPlaySound(sound, sound_level); float delay = llFrand(max_delay - min_delay) + min_delay; llSetTimerEvent(delay); } } } }
|
|
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
|
10-24-2006 12:45
Just took a quick glance; you seem to have set the timer properly, but you need to have a timer() event handler to actually execute the code when the timer fires. http://www.lslwiki.com/lslwiki/wakka.php?wakka=timer
|
|
Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
|
10-24-2006 13:55
I'm still having trouble understanding what I need to do, if you know what is missing or wrong please see if you can fix it. I would greatly appreciate it. I'm just starting out in scripting and still have a lot of walls to climb. 
|
|
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
|
10-24-2006 14:17
Sure Alicia, the script is actually well done and 99% complete - just missing one thing. I took out your comments and put a couple of my own in to make things clearer. integer group = FALSE; integer anyone = FALSE; integer on = FALSE; float min_delay = 30; float max_delay = 30; float sound_level = 1.0;
integer allowed( key lid ) { if ( lid == llGetOwner() ) {return TRUE;} if ( group ) { if ( llSameGroup( lid ) ) {return TRUE;} } if ( anyone ) {return TRUE;} return FALSE; }
init() { group = FALSE; anyone = FALSE; if ( llGetInventoryType( "allow_group" ) == INVENTORY_NOTECARD ) { group = TRUE; } if ( llGetInventoryType( "allow_anyone" ) == INVENTORY_NOTECARD ) { anyone = TRUE; } llStopSound(); on = FALSE; } default { state_entry() { init(); } on_rez( integer r ) { init(); } changed( integer c ) { if ( c & CHANGED_OWNER ) { llResetScript(); } } touch_start( integer t ) { if ( allowed( llDetectedKey(0) )) { if ( on ) { on = FALSE; llWhisper(0, "Sounds Off"); llStopSound(); llSetTimerEvent(0);// gotta stop the timer here as well as the sound } else { on = TRUE; llWhisper(0, "Sounds On"); llSetTimerEvent(1.0);// yes, here is where you start the timer } } } timer()// but here is where you put the stuff that happens when the timer goes off { integer num_sounds = llGetInventoryNumber(INVENTORY_SOUND); integer i = llFloor(llFrand(num_sounds)); string sound = llGetInventoryName(INVENTORY_SOUND, i); llPlaySound(sound, sound_level); float delay = llFrand(max_delay - min_delay) + min_delay; llSetTimerEvent(delay); } }
See, I moved the lines of code that actually find and play a sound into the timer() event handler down below. llSetTimerEvent(something) starts up the timer but that's all; from then on, every time the timer cycles, the timer() event handler is called and that's where you put all the stuff that needs to happen. The only other addition I made was to stop the timer (by specifying zero as the duration) when you click a second time, otherwise it will just keep going and going. Hope that helps.
|
|
Alicia Mounier
Registered User
Join date: 17 Oct 2005
Posts: 78
|
10-24-2006 14:35
ty sooooo much! I see what I was doing wrong i kept trying to add that timer() but it wouldn't save or still not randomly play. This works great! I also changed llWhisper to llOwnerSay. 
|