switching between sounds

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

switching between sounds

Post by creekmonkey » Mon Aug 11, 2008 5:15 am

Is it possible to switch between different sounds in a lowlevel command?

I have a vehicle that operates in lowlevel commands
accelerates when spacebar is pressed
brakes when B is pressed..............exct.

I was hoping to have a sound for acceleration, one for full speed, one for braking and deceleration.
I tried using

if(IsKeyDown(46))
{
if(speed<10)
{
PlaySound("accelerate.wav");
}

else
{
if(speed>10)
{
PlaySound("fullspeed.wav");
}
}
}

which kind of works....except i see no way of stopping accelerate.wav.
Am I overlooking something or is this not possible?

User avatar
steven8
Posts: 1487
Joined: Wed Aug 24, 2005 9:08 am
Location: Barberton, OH

Re: switching between sounds

Post by steven8 » Wed Aug 13, 2008 4:22 am

creekmonkey wrote:Is it possible to switch between different sounds in a lowlevel command?

I have a vehicle that operates in lowlevel commands
accelerates when spacebar is pressed
brakes when B is pressed..............exct.

I was hoping to have a sound for acceleration, one for full speed, one for braking and deceleration.
I tried using

if(IsKeyDown(46))
{
if(speed<10)
{
PlaySound("accelerate.wav");
}

else
{
if(speed>10)
{
PlaySound("fullspeed.wav");
}
}
}

which kind of works....except i see no way of stopping accelerate.wav.
Am I overlooking something or is this not possible?
I am not a scripter, but maybe: How about saying if the speed is greater than 1 or less than ten, play accelerate, else if speed is less than one, play no sound?
Steve Dilworth - Resisting change since 1965!

User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Re: switching between sounds

Post by creekmonkey » Wed Aug 13, 2008 4:32 am

My problem is the sounds are overlapping, once my wav file starts it doesnt stop until finished no matter what i try. It seems ther is no LowLevel command to stop sounds.

Im sure there is probably some way to make acceptable vehicle sounds, I just cant get it to work. Maybe Juutis, QOD, bernie or one of the other scripting gurus have had some luck with this.

User avatar
steven8
Posts: 1487
Joined: Wed Aug 24, 2005 9:08 am
Location: Barberton, OH

Re: switching between sounds

Post by steven8 » Wed Aug 13, 2008 4:40 am

Shoot. :(
Steve Dilworth - Resisting change since 1965!

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: switching between sounds

Post by Juutis » Wed Aug 13, 2008 10:49 am

Oh ya, I now I get your problem. I came up with a couple of possible solutions:

1.) Make the sounds very short.

2.) Add a timer so a new sound can only start when the old is finished. So for example if your sounds are 2 seconds long:

Code: Select all

if(soundtimer < time)
{

if(IsKeyDown(46))
{
if(speed<10)
{
PlaySound("accelerate.wav");
}

else
{
if(speed>10)
{
PlaySound("fullspeed.wav");
}
}
}

soundtimer = time + 2;
}
3.) I don't know if this works but using the AudioSource3D entity is one option. If turning the trigger for the entity off stops the sound immediately, it would work. But you'll have to test this yourself.
Pain is only psychological.

User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Re: switching between sounds

Post by creekmonkey » Thu Aug 14, 2008 12:02 am

I was able to get the sounds fairly close using the audiosource3d.
It took a lot of ugly scripting, but it works.
4 triggers
4 audiosorce3d entities
and a ton of SetEventState(char *Trigger, bool State ).
The sounds are not the best but its way closer than I was.

Post Reply