Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Awkward Silence

Tucker Flux
Registered User
Join date: 8 Dec 2009
Posts: 8
12-11-2009 16:19
Hi,

I have been working on a script to play sounds based on control inputs so that my car makes the right noises at the right time. The issue is it plays the sound repeatedly only playing the first quarter second of it or so. I tried to resolve this using timers and it works perfectly one time then the sounds don't play again for another 10 seconds or so.

Here is the bit I'm stuck on:
control(key id, integer held, integer diff)
{
vector linearMotor;
if (IN_GEAR == 1)
{
if (held & CONTROL_FWD)
{linearMotor.x = X_THRUST;
llSetTimerEvent(7.0);
ACCELERATING = ACCELERATING +1;
SOUND_THREE = SOUND_THREE + 1;
if (ACCELERATING == 1)
{llPlaySound("Accelerating", 1.0);}

}

else if (held & CONTROL_BACK)
{ linearMotor.x = -X_THRUST;
llSetTimerEvent(4.0);
DECELERATING = DECELERATING + 1;
SOUND_THREE = SOUND_THREE + 1;
if (DECELERATING == 1)
{llPlaySound("Slowing down", 1.0);
}}

else if (ACCELERATING == 0 && DECELERATING == 0 && SOUND_THREE != 0)
{ llLoopSound ("Throttle off", 1.0);

}

timer()
{
if (RUNNING == 1)
{llLoopSound("idle", 0.50);}//Plays idle loop
else if (ACCELERATING != 0) //&& DECELERATING == 0)
{llStopSound();
llLoopSound("Running loop", 1.0);
ACCELERATING = 1;
if (DECELERATING != 0)
{DECELERATING = 0;
SOUND_THREE = 1;
ACCELERATING = 0;
//else if (DECELERATING != 0 && ACCELERATING == 0)
//{DECELERATING = 1;}
//else
//{DECELERATING = 0;
//ACCELERATING = 0;}
//{llLoopSound("idle", 0.50);}//


Any suggestions would be appreciated. I am very confused.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
12-11-2009 16:29
There are some server side throttles on playing sounds. See if you are getting an error like "Too many sound system requests. Throttled until average falls." Control events are likely to start up a LOT of sound requests, so you are probably hitting that limit.

You might use a timestamp of some sort to decide if to play a new sound or wait it out.
Tucker Flux
Registered User
Join date: 8 Dec 2009
Posts: 8
12-11-2009 16:52
Thanks, I think you are right, is there some way to pause just a portion of the script? The timer is too complicated and not very effective, but llSleep pauses the whole script so I am not sure how to fix it.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
12-11-2009 17:01
You could use something like this as a replacement for your llPlaySound calls. This just throws away the extras.

CODE

SlowPlaySound(string sound, float length) {
if (llGetTime() > 0.5) { // experiment to find a a good delay
llPlaySound(sound, length);
llResetTime();
}
}


Another possibility is to use a different sound loop each time the vehicle switches actions (store the last one you used in a variable), and avoid the llPlaysound problem that way.