Jump to content

Play a sound Loop Only at 6 Knots of faster speed!


woogalie
 Share

You are about to reply to a thread that has been inactive for 2316 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello everyone, 

I am having trouble adding a component to my modified Becky's Bwind Script. I would like a sound loop to play ONLY when the boat is traveling at 6 knots or faster. 

Been trying to add if(speedvariable>6 ) llLoopSOund();

I believe the speedvariable in Becky's Bwind script is "currSpeed".

//linear motion variables
float currSpeed;
vector groundSpeed=ZERO_VECTOR;
float spdFactor=0.0;
float leeway;

Anyone have any advice for me?

Thanks!

Link to comment
Share on other sites

5 minutes ago, woogalie said:

Anyone have any advice for me?

Not much.  After all, who knows what Becky's Bwind script might be, or how it works?  Do remember, though, that llLoopSound will keep playing until you stop it with llStopSound.  And check your spelling.

Link to comment
Share on other sites

I'm not familiar with the script to which you refer, and the fragment of code you reproduce tells me nothing, I'm sorry to say, about how currSpeed is calculated.

However in general, if I want to know the speed I'm travelling at, I'd use llVecMag(llGetVel() / llGetRot()), which should tell me my forward velocity in metres/second.  

Edited by Innula Zenovka
Link to comment
Share on other sites

A simple search in the BWind script would have shown you the function calcSpeed() with groundSpeed which later is used in updateHUD() where wind speed in knots is calculated as llVecMag(groundSpeed*1.944) - use this an inspiration for your speed trigger.

Simple untested sample: Adding to end of the updateHUD() function should do the trick, define the variables at top of script.

float fTriggerKnotSpeed= 0.0;

float fOldSpeed= 0.0;

....

fTriggerKnotSpeed= llVecMag(groundSpeed*1.944);

if (fOldSpeed!=fTriggerKnotSpeed)

{

   fOldSpeed= fTriggerKnotSpeed;

   if (fTriggerKnotSpeed>=6.0) llLoopSound( MY_SOUND, 1.0);

   if (fTriggerKnotSpeed<6.0) llStopSound();

}

or one-liner:

if (llVecMag(groundSpeed*1.944)>6.0)llLoopSound( MY_SOUND, 1.0);

Notice, your llLoopSound could interfere with other loop sound in the boat, a simple solution is move your control to another prim and let the root prim send speed in a lllLinkMessage()

FYI: Becca Moulliez BWind is well known and regarded as best basic sail boat script for free use, if private non-profit usage.

Edited by Rachel1206
  • Like 2
Link to comment
Share on other sites

Thank you all so much for the input, even telling me that what I wrote does not compute, seriously! I am going to analyze the script and see if I can adapt what you provided into it this weekend. And hopefully understand it too, TY rachel1206! 

 

Will report what I find, it's become a lot of fun learning this stuff. 

Edited by woogalie
Link to comment
Share on other sites

I was able to fit it into the script and it works. I have two sounds, and they both toggle when greater or lower than 6 knots speed. Wonderful Rachel!

Like everything I build in second life, when I solve one problem I find a new one lol, the sound seems to keep looping at 1 second intervals, its definitely playing though!

Here is the code I implemented at the end of the updateHUD() section. Now I just gotta figure out how to get it to stop triggering every second and let the sound file loop properly.

   fTriggerKnotSpeed= llVecMag(groundSpeed*1.944);

if (fOldSpeed!=fTriggerKnotSpeed)

{

   fOldSpeed= fTriggerKnotSpeed;

   if (fTriggerKnotSpeed>=6.0)
   llLoopSound( "planing", 1.0);

   if (fTriggerKnotSpeed<6.0) llStopSound();
   
   if (fTriggerKnotSpeed<=6.0)
   llLoopSound( "sailing", 1.0);


}

 

I also defined these variables at the top of the script:

float fTriggerKnotSpeed= 0.0;
float fOldSpeed= 0.0;

Edited by woogalie
Link to comment
Share on other sites

Assuming that you are triggering that sound in a timer event, you may want to use llTriggerSound instead of llLoopSound.  After all, you don't want to keep restarting the loop each time the timer ticks.  You want to play a fresh sound.

Link to comment
Share on other sites

Interesting! Ty Rolig, this provided me something new to understand. Here is what I put and it causes the sounds to layer and build louder as time passes. 

fTriggerKnotSpeed= llVecMag(groundSpeed*1.944);

if (fOldSpeed!=fTriggerKnotSpeed)

{

   fOldSpeed= fTriggerKnotSpeed;

   if (fTriggerKnotSpeed>=6.0)
   llTriggerSound( "planing", 1.0);

   if (fTriggerKnotSpeed<6.0) llStopSound();
   
   if (fTriggerKnotSpeed<=6.0)
   llTriggerSound( "sailing", 1.0);


}

 

I believe the trigger is checking IF the speed is < or> 6  too often, is there a way to limit how often it checks if it should  llLoopSound or llTriggerSound?

Edited by woogalie
Link to comment
Share on other sites

Again, I do not know how your script works, so I am assuming that you are triggering the sounds in a timer event.  If so, the simple answer to your question is to slow down the timer.

A more complicated answer .....

I suggested using llTriggerSound because I was avoiding the challenge of stopping and starting llLoopSound, which takes a little more scripting skill.   If I were doing it myself, though, I would construct the timer event schematically like this:
 

timer()
{
    // If fTriggerKnotSpeed is less than 6.0 AND it was previously greater than 6.0, THEN llStopSound("planing" and llLoopSound("sailing")
    // Otherwise, if fTriggerKnotSpeed is less than 6.0, don't do anything (that is, don't stop looping "planing").
    // On the other hand, if fTriggerKnotSpeed is greater than 6.0 AND it was previously less than 6.0, THEN llStopSound("sailing") and llLoopSound("sailing")
    // Otherwise, if fTriggerKnotSpeed is greater than 6.0, don't do anything (that is, don't stop looping "sailing").
}

If you do it that way, you can run the timer at any convenient speed.  It will only change from looping one sound to looping the other when your speed crosses the 6.0 threshhold.

Link to comment
Share on other sites

Ok someone tell me if this is dumb or what...

I added integer tick8 = 8; to my list at top of script

then I added the llSetTimerEvent(tick8); to the script and it allows the sound clip to play a decent length before looping but my entire boat operates at an 8 sec interval, pulling sails in/out. I will figure out how to limit how often the sound plays soon, just do what I mean! :D

 

fTriggerKnotSpeed= llVecMag(groundSpeed*1.944);
 
if (fOldSpeed!=fTriggerKnotSpeed)
llSetTimerEvent(tick8);
{

   fOldSpeed= fTriggerKnotSpeed;
   
   if (fTriggerKnotSpeed>=6.0)
   llLoopSound( "planing", 1.0);

   if (fTriggerKnotSpeed<6.0) llStopSound();
   
   if (fTriggerKnotSpeed<=6.0)
   llLoopSound( "sailing", 1.0);


}

Link to comment
Share on other sites

9 minutes ago, woogalie said:

Ok someone tell me if this is dumb or what...

Well, not dumb, but inefficient and possibly clunky.  That will slow down the timer properly, but if you leave llLoopSound in the timer event, you will be resetting it every 8 seconds.  That's less efficient than simply using llTriggerSound every 8 seconds and it's way less efficient than changing the sound only when speed changes.

Edited by Rolig Loon
Link to comment
Share on other sites

SOLVED!

VERY big Thanks to Rachel1206 and Rolig for keeping me at it!

I was able to get this to work by simply adding what Rachel1206 suggested as the one-liner. 

Oh Becky's Bwind BBK - 1-37-44 (Release) script, starting on line 522 you will see:

// UPDATE HUD - Main HUD routine and colour management
updateHUD() {
    string dataString;
    float compass=PI_BY_TWO-zRotAngle;
    float effcoeff;
    
    string rgn = llGetRegionName();
    string blank = " ";
    float efficiency;
    string ratio;
    float derivatesheetAngle=sheetAngle;

 

When I added the one-liner that Rachel1206 suggested below the last float, everything worked. The sound clips play their full duration AND they toggle when my boat speed rises or drops between 6 knots speed. Below is how it should look with Rachel1206 awesome one-liners implemented.

// UPDATE HUD - Main HUD routine and colour management
updateHUD() {
    string dataString;
    float compass=PI_BY_TWO-zRotAngle;
    float effcoeff;
    
    string rgn = llGetRegionName();
    string blank = " ";
    float efficiency;
    string ratio;
    float derivatesheetAngle=sheetAngle;
    
   if (llVecMag(groundSpeed*1.944)<6.0)llLoopSound( "sailing", 1.0);
   if (llVecMag(groundSpeed*1.944)>6.0)llLoopSound( "planing", 1.0);

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2316 days.

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
 Share

×
×
  • Create New...