Sound issue of sorts


(Nate ) #1

Hey guys!

So I have a player who gets shot by enemies. He emits a low guttural sound when he is shot. It ran totally fine when the enemies were all shooting semi-automatic. But I recently switched them to fire controlled bursts as well a fully automatic.

The issue as you may have guessed is, having the low guttural sound play when someone barrages the player with fully automatic fire causes the sound to SUPER LOOP and is very annoying.

Is there some way I could make it so the sound only happens once when a barrage of bullets is unleashed on the player? Or say the sound goes off once every 5 seconds WHILE under fire?

Something like that? I have done a little messing around with alarms but I am not sure if that is the route I want to go, and they make my brain ache sometimes lol.

Please let me know what you think guys! Thank you!


(JP Mortiboys) #2

Try this:

public class PlayerWhoGetsShotByEnemies {
  private var lowGutteralSound:Sound;
  private var canUtterlLowGutteralSound:Boolean = true;

  public function takeThatYouZombie(damage:int):void {
    // health, knockback, whatever...
    if (canUtterLowGutteralSound) {
      lowGutteralSound.play();
      canUtterLowGutteralSound = false;
      addTween(new Alarm(5, youMaySpeakAgain, ONESHOT));
    }
  }

  private function youMaySpeakAgain():void {
    canUtterLowGutteralSound = true;
  }
}

(Nate ) #3

I was unaware of ONESHOT, does that make it just go once? I was using PERSIST.

Using your set up I still can’t get it to work. I have the if(isplaying) portion of your code inside of my collision code for my bullet then I have the youMaySpeakAgain code, when I trace isPlaying is just always says False, so I am guessing it isn’t getting the chance to switch to true inside of my update method?


(JP Mortiboys) #4

If you’re not sure if that code is being executed, put a breakpoint on that line and see if it fires.


(Nate ) #5

On which line? the sfxShot.play(.5) line?


(JP Mortiboys) #6

On this line:

canUtterLowGutteralSound = true;


(Nate ) #7

This is going to sound funny… how does one put a breakpoint on this line? I thought I just had to add break; after it but that says Target of break statement was not found


(JP Mortiboys) #8

In FlashDevelop, click to the left of the line number; a red dot should appear.


(Nate ) #9

Okay it looks like it does turn red and it might be firing but nothing plays. I am wondering if that is just because it is happening so quickly?


(Jacob Albano) #10

When the breakpoint is hit the game will pause and switch back to Flashdevelop. If that isn’t happening, it means the code is never being run.


(Jacob Albano) #11

Ah, I think I see the problem; you need to pass true as the second parameter to addTween() to make the alarm start immediately.

addTween(new Alarm(5, youMaySpeakAgain, ONESHOT), true);

(Nate ) #12

Okay it is not working then… lol I guess something else was tracing… I have a bad habit of wanting to trace everything… then not going back and removing the traces… then 30 classes later I have no idea where they are lol


(Jacob Albano) #13

You might have missed my double post there. I think it should fix your problem.

Also, in Flashdevelop Control+i will open the project search dialogue, so you can search for “trace(” and find all occurrences in all files.


(Nate ) #14

Okay thanks Jacob! I was not aware of this!

The set up is still currently not working D:

This is my update:

if (collide("zombie", x, y - 1) || collide("zombie", x + 1, y) || collide("zombie", x -1, y) || collide("zombie", x, y + 1))
		{
			FP.world.recycle(this);
			theZomb.health = theZomb.health - 7;
			
			
			if (isPlaying == false)
			{
				sfxShot.play(.5);
				isPlaying = true;
				addTween(new Alarm(4, youMaySpeakAgain, ONESHOT), true);
			}

This is my youMaySpeakAgain function:

		private function youMaySpeakAgain():void
	{
		isPlaying = true;
	}

(JP Mortiboys) #15

If you’ve inversed the logic and are using isPlaying, surely you want to set it to false in youMaySpeakAgain, not to true,


(Nate ) #16

Okay I am not sure how I missed that… lol So I just switched it and it is still just playing a million times when I get shot D:


(Jacob Albano) #17

Is there any point where you’re telling the sound to play that isn’t inside a check to see if it’s already playing?


(Nate ) #18

There is not. Do you think it has something to do with having the check inside of the collide?