Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Snake on Sun 03/01/2010 21:07:21

Title: Having trouble playing a sound repeatedly as an object animates...
Post by: Snake on Sun 03/01/2010 21:07:21
I'm sure this is childsplay to the rest of you, but for the life of me I cannot get this to work. I've tried several different versions of scripting this, but the sound plays once and stops.

So the thing is, I have probes with electricity flowing between them. I have a "bzzz" sound that I want played as long as this object is animating and then stops once the objects stops animating.

From rep_exec:


if ((IsSoundPlaying()==0)&&(object[9].Animating==true)){
  PlaySound(11);
}


That was the last bit of code I tried, which was a LAST RESORT idea, after several attempts. I'm too frustrated right now to rewrite all the different tries I did.

If you could plese point me in the right direction and tell me what I'm NOT doing, it will be MUCH appreciated.
Title: Re: Having trouble playing a sound repeatedly as an object animates...
Post by: NsMn on Sun 03/01/2010 21:09:57
Hmm, couldn't you just use


PlayAmbientSound();

?

Of course, you'd have to move the script from rep_execute, or it won't work right.
Title: Re: Having trouble playing a sound repeatedly as an object animates...
Post by: Kweepa on Sun 03/01/2010 21:18:28

bool isBuzzPlaying = false;

function player_enters_room()
{
 isBuzzPlaying = false;
}

function rep_ex()
{
 if (object[9].Animating && !isBuzzPlaying)
 {
   aSound9.Play();
   isBuzzPlaying = true;
 }
 else
 if (!object[9].Animating && isBuzzPlaying)
 {
   aSound9.Stop();
   isBuzzPlaying = false;
 }
}

function player_leaves_room()
{
 if (isBuzzPlaying)
 {
   aSound9.Stop();
 }
}


This requires AGS 3.2 to work though.
Otherwise it might be easiest to just time the animation and make the sound effect the same length.
Title: Re: Having trouble playing a sound repeatedly as an object animates...
Post by: Snake on Sun 03/01/2010 21:23:57
Oh, for Christ's sakes. Maybe I should have read the manual. (http://www.adventuregamestudio.co.uk/manual/)

Thanks, NsMn. I saw that in there too but bypassed it looking for IsSoundPlaying();...

\--EDIT--\
Thank you to you too, Steve, but PlayAmbientSound worked perfectly.

Heh, the code you gave me looked a lot like what I had already tried, except, I'm sure your version actually works ;)