Having trouble playing a sound repeatedly as an object animates...

Started by Snake, Sun 03/01/2010 21:07:21

Previous topic - Next topic

Snake

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:

Code: ags

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.
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

NsMn

Hmm, couldn't you just use

Code: ags

PlayAmbientSound();

?

Of course, you'd have to move the script from rep_execute, or it won't work right.

Kweepa

Code: ags

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.
Still waiting for Purity of the Surf II

Snake

Oh, for Christ's sakes. Maybe I should have read the 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 ;)
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

SMF spam blocked by CleanTalk