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.