• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Heavy Breathing sound

Youg

Grizzled Veteran
Jan 19, 2013
60
0
Hi,

If you've seen my other coding post then you may know what this is all about. I'm trying to print to a text file whenever the HeavyBreathing sound starts playing, I believe I found the right variable, if thats the right terminology. Here's the code I was trying to implement, though as far as I can see the compiler doesn't like the "()" part though without it, it doesn't like any of the statement.

Code:
    if( MyPawn.HeavyBreathingSound.IsPlaying() )
    {
     self.writer.Logf("Heavy Breathing:" $TimeStamp());
    }

Any ideas on why its not working?
 
Okay, after messing around for a bit I managed to get some code that compiled and on occassion, printed to a text file. Though it wasn't every time the sound was active. Any suggestions on what to try next?

I was going to look at moving the if statement to within the else, or outside of the bIsSprinting if completely and put it underneath, though haven't got the time at the moment to try, so any suggestions to look at would be great!

Code:
 if(self.bPreviousIsSprinting != MyPawn.bIsSprinting)
 {
  if(MyPawn.bIsSprinting)
  {
   self.writer.Logf("Player Started Sprinting:"$TimeStamp());
 
   //in an if statement whether the soundcue was activated
   if(MyPawn.HeavyBreathingSound.IsPlaying())
   {
    self.writer.Logf("Heavy Breathing:" $TimeStamp());
   }
  }
  else
  {
 
   self.writer.Logf("Player Stopped:"$TimeStamp());
   self.writer.Logf("Stamina Remaining:" @ MyPawn.Stamina);
  }
 
  self.bPreviousIsSprinting = MyPawn.bIsSprinting;
 }
 
Upvote 0
Because it will only hit that heavy breating line if the player changed from walking to sprinting. The first 'if' ensures that the inner code is only called on a transaction from walking -> sprinting or sprinting -> walking. The second 'if' ensures that the inner code will only be called if sprinting. The combination of those two makes the inner part being called 'if transaction from walking -> sprinting'. In most cases the heavy breathing won't be active yet at that time of the event.
 
Upvote 0
Another question when it comes to the heavy breathing. I'm trying to set it to start earlier than it currently does. This is what I was thinking of:

Code:
 if( MyPawn.Stamina =< 40)
 {
  self.writer.Logf("Stamina Reached"$TimeStamp());
  MyPawn.HeavyBreathing.IsPlaying();
 }

This currently sits at the bottom of the if(self.bPreviousIsSprinting != MyPawn.bIsSprinting) though I get one error about a mismatch in the IF statement. I believe its referencing the "MyPawn.HeavyBreathing...." as this won't set it to playing just when it is playing.

Any suggestions on what to put instead? I can't seem to find much in the ROPawn class.

Also I got the heavy breathing logging thanks ducky for the help!
 
Upvote 0
Just ran the compiler again, and the error relates to the actual IF(My.Pawn.Stamina =<40) part, don't have much of an idea myself as to why...

That should be:
Code:
IF (My.Pawn.Stamina [COLOR=yellow][B]<=[/B][/COLOR] 40)

Edit:
By the way, this
Code:
MyPawn.HeavyBreathing.IsPlaying();
will not do anything in that context, because it only tests if the heavy breathing sound cue is started or not. It does not start the sound cue. Please take a look at the AudioComponent class in Engine to understand the audio cue interface.
 
Last edited:
Upvote 0
ah okay, would this mean that a new class would be needed to extend the AudioComponent? Or would it be as simple as the MyPawn = ROPawn(Other); line to call it in the function? So MyAudio = AudioComponent (Other);



Edit:

Okay so I think I found an answer, instead of IsPlaying() it seems to be just Play() to start the audio. So I've changed the code now to

MyPawn.HeavyBreathingSound.Play();

Giving this a go now.
 
Last edited:
Upvote 0
So I tried a few variants on this code:

Code:
function LogSprintTransition(Pawn Other)
{
    local ROPawn MyPawn;
    MyPawn = ROPawn(Other);
 
 MyPawn.SprintFootStepVolume = 10;
 
 if(self.bPreviousIsSprinting != MyPawn.bIsSprinting)
 {
 
  if(MyPawn.bIsSprinting)
  {
   self.writer.Logf("Player Started Sprinting:"$TimeStamp());
   
[COLOR=yellow]   if( MyPawn.Stamina < 40.0)
   {
    MyPawn.HeavyBreathingSound.Play();
    self.writer.Logf("Stamina Limit Reached"$TimeStamp());[/COLOR]
[COLOR=yellow]   }[/COLOR]
  }
  else
  {
   self.writer.Logf("Player Stopped:"$TimeStamp());
   self.writer.Logf("Stamina Remaining:" @ MyPawn.Stamina);
  }
   
  self.bPreviousIsSprinting = MyPawn.bIsSprinting;
 }
}

that being the current build and it doesn't seem to work. I've had it log once that its gone into the IF(Stamina < 40.0) statement but it hasn't activated the heavybreathingsound. Variants I've tried has mainly involved moving the if statement out of the IF(Self.bPrevious...) statement or a in it and not inside one of the others. Any suggestions?
 
Upvote 0
So I tried a few variants on this code:

Code:
function LogSprintTransition(Pawn Other)
{
    local ROPawn MyPawn;
    MyPawn = ROPawn(Other);
 
 MyPawn.SprintFootStepVolume = 10;
 
 if(self.bPreviousIsSprinting != MyPawn.bIsSprinting)
 {
 
  if(MyPawn.bIsSprinting)
  {
   self.writer.Logf("Player Started Sprinting:"$TimeStamp());
   
[COLOR=yellow]   if( MyPawn.Stamina < 40.0)
   {
    MyPawn.HeavyBreathingSound.Play();
    self.writer.Logf("Stamina Limit Reached"$TimeStamp());[/COLOR]
[COLOR=yellow]   }[/COLOR]
  }
  else
  {
   self.writer.Logf("Player Stopped:"$TimeStamp());
   self.writer.Logf("Stamina Remaining:" @ MyPawn.Stamina);
  }
   
  self.bPreviousIsSprinting = MyPawn.bIsSprinting;
 }
}
that being the current build and it doesn't seem to work. I've had it log once that its gone into the IF(Stamina < 40.0) statement but it hasn't activated the heavybreathingsound. Variants I've tried has mainly involved moving the if statement out of the IF(Self.bPrevious...) statement or a in it and not inside one of the others. Any suggestions?

That code block will only if a player starts sprinting. That is why you only see that log line once.

Code:
function LogSprintTransition(Pawn Other)
{
    local ROPawn MyPawn;
    MyPawn = ROPawn(Other);
 
    MyPawn.SprintFootStepVolume = 10;
 
    if(self.bPreviousIsSprinting != MyPawn.bIsSprinting)
    {
 
        if(MyPawn.bIsSprinting)
        {
            self.writer.Logf("Player Started Sprinting:"$TimeStamp());
        }
        else
        {
            self.writer.Logf("Player Stopped:"$TimeStamp());
            self.writer.Logf("Stamina Remaining:" @ MyPawn.Stamina);
        }
   
        self.bPreviousIsSprinting = MyPawn.bIsSprinting;
    }

[COLOR=yellow]    if((MyPawn.Stamina < 40.0) && ![/COLOR][COLOR=yellow][COLOR=yellow]MyPawn.HeavyBreathingSound.IsPlaying()[/COLOR])
    {
        MyPawn.HeavyBreathingSound.Play();
        self.writer.Logf("Stamina Limit Reached"$TimeStamp());[/COLOR]
[COLOR=yellow]    }[/COLOR]

}

It can be that somewhere else in the code (in one of the TWI files) the sound cue is stopped from playing if they detect it is playing while it shouldn't.
 
Last edited:
Upvote 0
ah, so what if it is a TWI file that is stopping it from playing? Would I need to add that to the if variables?

if((MyPawn.Stamina < 40.0) && !MyPawn.HeavyBreathingSound.IsPlaying() && !TWI.Stop)

sort of thing?

Not even close, Stop is a function that doesn't return a value. This means you can't use it in an equation. If a TWI file stops the sound cue, then you need to figure out where it is stopped and try to out-smart that TWI code. It often means that you will need to make a sub class of the TWI class in question and override the function in which the sound cue is stopped.
 
Upvote 0
okay, so if there is a TWI file, I'll have a look around and I guess I'll have to do the class MyBreathingController extends TWIFile; to override the function.

The reason I say if is because I'm getting an error to do with the line

Code:
MyPawn.FootStepVolume  = 10.0

now previously it was SprintFootStepVolume, but there is no such thing in the ROPawn class so I changed it to be what its stated within the ROPawn, though that is when I got my error. I looked at the code again and saw that it's a local float inside a simulated function called PlayFootStepVolume so I changed it to:

Code:
MyPawn.PlayFootStepVolume.FootStepVolume = 10.0

though I no get an error which points to the second "." being unexpected, any suggestions on what I need to do?
 
Upvote 0
okay, so if there is a TWI file, I'll have a look around and I guess I'll have to do the class MyBreathingController extends TWIFile; to override the function.

The reason I say if is because I'm getting an error to do with the line

Code:
MyPawn.FootStepVolume  = 10.0

now previously it was SprintFootStepVolume, but there is no such thing in the ROPawn class so I changed it to be what its stated within the ROPawn, though that is when I got my error. I looked at the code again and saw that it's a local float inside a simulated function called PlayFootStepVolume so I changed it to:

Code:
MyPawn.PlayFootStepVolume.FootStepVolume = 10.0

though I no get an error which points to the second "." being unexpected, any suggestions on what I need to do?

A local declared variable is only exposed to the function in which it is declared. It does not even exist anymore after execution of the function. You can only access variables declared in the head of a class (those that start with var). This rule fits for any programming languages.

ROPawn has the next declarations:
Code:
var()   float                           SprintFootStepVolume;	// Footstep volume for sprinting
var()   float                           WalkFootStepVolume; 	// Footstep volume for walking
var()   float                           CrouchFootStepVolume;	// Footstep volume for crouching
var()   float                           ProneFootStepVolume;	// Footstep volume for proning
var()   float  							CrouchVolumeModifier;	// Modifier for crouch walking and sprinting

Those you can access using for instance ROPawn.WalkFootStepVolume.
There simply is no FootStepVolume. You can't acces what isn't there.

Thre also is no ROPawn.PlayFootStepVolume. There is a ROPawn.PlayFootStepSound, but that is a function and not an object.
 
Upvote 0
thats where I must of got SprintFootStepVolume from. Anyway I just tested the Stamina Limit and it doesn't play, so it must be a TWI file that is stopping it from execute.

It does go into the if statement, though produces a log every second and even when stamina is 100, i was thinking of adding a bool into the sprint IF to turn true activating the if stamina one which will set it to false. So something like this:

Code:
if(self.bPreviousIsSprinting != MyPawn.bIsSprinting)
 {
 
  if(MyPawn.bIsSprinting)
  {
   self.writer.Logf("Player Started Sprinting:"$TimeStamp());
[COLOR=yellow]   if(MyPawn.Stamina < 40.0)[/COLOR]
[COLOR=yellow]   {[/COLOR]
[COLOR=yellow]       staminathreshold = true;[/COLOR]
[COLOR=yellow]   }[/COLOR]
  }
  else
  {
 
   self.writer.Logf("Player Stopped:"$TimeStamp());
   self.writer.Logf("Stamina Remaining:" @ MyPawn.Stamina);
  }
 
  self.bPreviousIsSprinting = MyPawn.bIsSprinting;
 }
 
 //Start playing the HeavyBreathingSound
 if((MyPawn.Stamina < 40.0) && !MyPawn.HeavyBreathingSound.IsPlaying() [COLOR=yellow]&& staminaThreshold = true[/COLOR])
    {
        MyPawn.HeavyBreathingSound.Play();
        self.writer.Logf("Stamina Limit Reached"$TimeStamp());
        [COLOR=yellow]staminaThreshold = false;[/COLOR]
    }

The way I understand it as this should mean that it'll only go into this if the player has started sprinting and is below 40.0
 
Upvote 0