llLoopSound at night only
|
|
Tyrehl Byk
Registered User
Join date: 4 Dec 2008
Posts: 24
|
02-17-2009 09:40
I'm in over my head with scripting and this seems like a simple syntax thing that I simply cannot get my head around.
I want a simple script that will start a llLoopSound at sunset, and then stop it at sunrise.
I have a script that runs a loop indefinitely, and I have a script that will play random sounds at random intervals from the prim inventory only at night time.
I'm simply out of my depth when trying to combine the two into a simple on/off loop for a single sound.
HELP PLEASE!
---Bows to the masters at hand
Tyrehl
|
|
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
|
02-17-2009 09:55
I think you will need a regular timer (shouldn't need to be more often than once a minute), and use it to check the sun direction. As soon as it detects the sun has set, it should start looping the sound, and as soon as it detects sunrise, it should stop the sound.
|
|
Tyrehl Byk
Registered User
Join date: 4 Dec 2008
Posts: 24
|
02-17-2009 10:32
Thanks Pedro, I was able to understand that concept from looking at the scripts I have. My difficulty comes from not having the scripting experience to write the proper syntax. As I see it, I have edit my loop script to introduce: vector sun_point = llGetSunDirection(); if ( sun_point.z >= 0.0 ) state silent; Unfortunately, I've tried in vain to figure out how to place it and can't get something that compiles properly. I'm really out of my depth here. Could someone please show me how to make the syntax work? I imagine that this is a bloody simple thing, and will understand it once I see it, but I simply don't have the experience to make it work. Currently the loop script reads: (forgive me if this is not formatted properly for the forum) // Sound Prim Script - Loop // // Repeatly plays the sound in inventory if there is // ONE and ONLY ONE sound. Silent otherwise. // // Set this between 0.0 and 1.0 float LOUDNESS = 0.5; // //////////////////////////////////////////////// Noisy() { if ( llGetInventoryNumber(INVENTORY_SOUND) == 1 ) { string soundname = llGetInventoryName(INVENTORY_SOUND, 0); if ( soundname != "" ) { llLoopSound( soundname, LOUDNESS ); } } else { llStopSound(); } } //////////////////////////////////////////////// default {
state_entry() { llStopSound(); Noisy(); }
changed(integer change) { if (change & CHANGED_INVENTORY) { llStopSound(); Noisy(); } }
}
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
Rough outline...
02-17-2009 11:04
Sorry, don't have time for details...
default { state_entry() { llSetTimerEvent(300); //every five minutes }
timer() { if Sun is up llStopSound() else llStartSound() }
} //end of default state.
This assumes that multiple llStartSound is not a problem.
_____________________
So many monkeys, so little Shakespeare.
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
02-17-2009 12:10
This should be all you need. It might contain a compile error, as I didn't run it through the compiler. But it's just a simple check, if the sun is down, it'll loop the sound, if it's up, it will stop the sound.
integer bPlayingSound = FALSE; //don't call llLoopSound while it's already looping.
integer SunDown() { vector sunDirection = llGetSunDirection(); if(sunDirection.z <= 0.0) {
return TRUE; } else return FALSE; }
default { state_entry() { llSetTimerEvent(300); //every 5 minutes }
timer() { if(SunDown() ) { if(!bPlayingSound) { llLoopSound(gSoundKey, gVolume); bPlayingSound = TRUE; } } else { llStopSound(); bPlayingSound = FALSE; } } }
|
|
Tyrehl Byk
Registered User
Join date: 4 Dec 2008
Posts: 24
|
02-17-2009 12:17
I appreciate your effort, Lee, but someone with my level of experience needs the details. I spent an hour with your response and I'm no closer to understanding how it fits in with what I currently have than I did before. I understand that the script I provided was written three years ago and style may have changed somewhat since then, but all I'm trying to do is regulate a currently existing script, not write a new one. The current script was written to work with any single sound dropped into the prim. All I want to change is to have the script speak up at sunset, and shut the hell up at sunrise.  It is painfully clear to me that script writing is about the details. It is my hope that someone who has a bit more time to handhold a noob might step up and provide a little more clairty. Thanks in advance.. Tyrehl
|
|
Tyrehl Byk
Registered User
Join date: 4 Dec 2008
Posts: 24
|
02-17-2009 12:20
Thanks Lazink,
I'll take what you gave and work the problem some more...
T
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
02-17-2009 13:00
Note that Lazink's script has left two variables to be given values in llLoopSound(gSoundKey, gVolume);
You'll need to set gVolume = 1 or just write llLoopSound(gSoundKey,1);
If you want to grab gSoundKey from the sound file you have dropped in the object, you can do that by adding string gSound = llGetInventoryName(INVENTORY_SOUND, 0); key gSoundKey = llGetInventoryKey(gSound);
to state_entry. If you want to avoid having the script hang if you forgot to put a sound file in the object, just add a test like if (gSoundKey == NULL_KEY) {return;}
to it. EDIT: Oh, and gSoundKey will need to be a global variable.
|
|
Tyrehl Byk
Registered User
Join date: 4 Dec 2008
Posts: 24
|
02-17-2009 13:19
Thank's Lazink
I'm a bit closer, and my understanding is increasing, but still no joy.
2 things...
First a really noob one...how is one supposed to reestablish the tabs in a script copied from this board and pasted into the compiler in SL? Everything is left justified and that makes it very hard to learn anything about scripting style. (or see what's going on) the colors are there, but the tabs are absent and I don't want to begin scripting with bad style.
Second, what you provided is terrific but hangs on the llLoopSound parameters gSoundKey, gVolume.
Again, I have to say that what I'm trying to do is use THE ORIGINAL LOOP SCRIPT (posted above) and MODIFY it. It was designed to look at the prim inventory, get the name of whatever sound is in there, and use it. Volume is controlled at the top of the script.
Once this thing is modified to run only when the sun is down, I should never have to alter anything in the script except the first line where the volume is set. I can drop any sound into the prim, set the volume and be done with it.
Getting closer....
T
|
|
Tyrehl Byk
Registered User
Join date: 4 Dec 2008
Posts: 24
|
02-17-2009 13:20
Man am I a man out of sync!!! That's twice I've replied at the same time a new reply was coming in... 
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
02-17-2009 13:32
 I should have mentioned that you can still include a changed event, the way you did in your original script. That would give you a little more flexibility in case you want to change sound files on the fly. You'll just want changed(integer change) { if (change & CHANGED_INVENTORY) { llResetScript(); } }
Oh, and to get a copiable script from a forum post, properly indented ...... Just hit the Quote button. The script should be indented correctly in the new window.
|
|
Tyrehl Byk
Registered User
Join date: 4 Dec 2008
Posts: 24
|
02-17-2009 15:31
From: Rolig Loon  I should have mentioned that you can still include a changed event, the way you did in your original script. That would give you a little more flexibility in case you want to change sound files on the fly. You'll just want changed(integer change) { if (change & CHANGED_INVENTORY) { llResetScript(); } }
HEEEEYyyyy Rolig...I'm so close I can taste it and boy, have I learned a thing or two, thank you very much!!!! First, if you take a look at my original script, there was a float function at the top that let me change the voulme without burrowing down into the script. It would seem (noob speculation) that the float value, named the Y variable specified in the llLoopSound(x,y) "LOUDNESS" as designated in the original script. I seem to be lost as to how to name that variable so that it can float up top as in the original script. So far we've just about re-written the original and it compiles fine, but I can't seem to get this to function. Also...I've tried placing the changed event string into the script but can't seem to get it to compile without an error on the very last line. I'm not quite certain as to exactly where to place it Currently the compiled script reads as follows: (naturally I'll be replacing the header text once that is sorted out.
// Sound Prim Script -Night Loop // // Repeatly plays the sound in inventory only at night. // // Set this between 0.0 and 1.0 //float LOUDNESS = 0.5; // //////////////////////////////////////////////// integer bPlayingSound = FALSE; //don't call llLoopSound while it's already looping.
integer SunDown() { vector sunDirection = llGetSunDirection(); if(sunDirection.z <= 0.0) {
return TRUE; } else return FALSE; }
default { state_entry() { llSetTimerEvent(300); //every 5 minutes }
timer() { if(SunDown() ) { if(!bPlayingSound) { string gSound = llGetInventoryName(INVENTORY_SOUND, 1); key gSoundKey = llGetInventoryKey(gSound); llLoopSound(gSoundKey, 1); bPlayingSound = TRUE; } } else { llStopSound(); bPlayingSound = FALSE; } } } [
|
|
Tyrehl Byk
Registered User
Join date: 4 Dec 2008
Posts: 24
|
02-17-2009 15:53
Grrrrrrrr.... Doesn't matter yet, the script as posted compiles fine, but there is a run error saying that it can't find the sound: '00000000-0000-0000-0000-000000000000' <sigh> Raw HTML is a breeze compared to this... 
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
02-17-2009 16:01
Sorry about the earlier one, was a quick write up. This compiles in world, and should work. I put in a lot of commenting so you can understand what is going on. // Sound Prim Script - Loop // // Repeatly plays the sound in inventory if there is // ONE and ONLY ONE sound. Silent otherwise. // // Set this between 0.0 and 1.0
//Volume float LOUDNESS = 0.5;
//Sound Name Global Variable string gSoundName = "";
//Boolean Check integer bSoundOff = TRUE;
//Name: SunDown //Desc: Checks to see if the sun is below the horizon. //Input: None. //Output: TRUE if the sun is below the horizon. // FALSE is the sun is above the horizon. //Usage: if(SunDown()) integer SunDown() { //Get the suns direction vector sunPosition = llGetSunDirection(); //If the sun is below the horizon if(sunPosition.z <= 0.0) { return TRUE; } //Sun is above the horizon. else return FALSE; }
//Name: SoundInInventory() //Desc: Checks to see if there is a sound file in the inventory // of the object. //Input: None. //Output: TRUE if there is a sound in the inventory, and assigns // that sound name to gSoundName. Only the first sound found // in the inventory is assigned to gSoundName. If no sound is // found, gSoundName is assigned an empty string. //Usage: if(SoundInInventory()) integer SoundInInventory() { //Get the number of sound files in the inventory integer numberOfSounds = llGetInventoryNumber(INVENTORY_SOUND); //Check to see if there is 1 or more sounds in the inventory if(numberOfSounds > 0) { //The first sound file in the inventory is assigned to gSoundName gSoundName = llGetInventoryName(INVENTORY_SOUND, 0); return TRUE; } else { //No sound file found in the inventory, setting gSoundName to an empty string. gSoundName = ""; return FALSE; } }
//Name: CheckSun //Desc: Runs a check on the sun position, and if it's found to be below // the horizon, checks to play the sound in the inventory. //Input: None //Output: If the sun is below the horizon, and the sound is not playing // it will start up the sound. //Usage: CheckSun(); CheckSun() { if(SunDown()) { //Check to see if the sound is already playing if(bSoundOff) { //Sound not playing, sun is below the horizon, start looping the sound llLoopSound(gSoundName, LOUDNESS); //Make bSoundOff false, so we don't try to keep looping the sound when already playing. bSoundOff = FALSE; } } else { //Sun was found to be above the horizon, stop the sound. llStopSound(); //Make bSoundOff true, because the sound is now off. bSoundOff = TRUE; } }
default {
state_entry() { //Run a check at the start to see if there is a sound in the inventory if(SoundInInventory()) { //Run an initial check to start right away if script started while sun is down. CheckSun(); //Set a timer to go off every 5 minutes. llSetTimerEvent(300); } } on_rez(integer start_param) { //Object rezzed, reset the script. llResetScript(); } timer() { //Check the sun positon and sound playing CheckSun(); }
changed(integer change) { //Detected a change in the inventory if (change & CHANGED_INVENTORY) { //Check to see if the change was a sound file. if( ! SoundInInventory() ) { //No sound files found in the inventory, shutting off the timer. llSetTimerEvent(0); } else { //Reset the script, to go back to the state_entry. llResetScript(); } } } }
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
02-17-2009 16:04
That's because you told it to look for the second sound file in the objct instead of the first one. Objects in inventory are indexed starting with zero. That's why the code I gave you said string gSound = llGetInventoryName(INVENTORY_SOUND, 0);
As for changing the sound volume...... you can certainly use the variable LOUDNESS as you have written it, but you will have to remove the double slashes in front of that line to make it active. It's a comment as written. You will also need to put LOUDNESS into your llLoopSound statement .... llLoopSound(gSoundKey, LOUDNESS);
That should do the trick.
|
|
Tyrehl Byk
Registered User
Join date: 4 Dec 2008
Posts: 24
|
02-18-2009 07:55
Thank you both Rolig and Lazink,
Not having a programming background makes grasping the conceptual part of scripting and how events relate to each other somewhat of a mystery right now. Your patience has been greatly appreciated.
The last script you provided, Lazink makes things a bit easier to understand and functions almost perfectly. It does seem to be missing one piece of information that would turn the llLoopSound off at Sunrise.
I'll sit with it for a while and see if I can determine where the missing detail is. It will be helpful for me to study this for a while and let some of the learning sink in.
Thanks again!
T
|