Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sound playing in area
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#8
RE: sound playing in area

Just wanted to offer a quick explanation - when you use if...else statements, it ensures that only one of the pieces of code will run (i.e. the code in the 'if' or the code in the 'else'). That applies to if... else if statements as well (the 'else if' is for checking another condition)

However, when you use 'if' and then another 'if' instead of an 'else', it is possible for the code for both if's to run. This can create some nasty bugs if both of your statements turn out to be true (impossible in this example, but very possible elsewhere)

It is therefore much more secure to use this method in the future
void PlayerCollideSound(string &in asParent, string &in asChild, int alState)
{
   if(alState == 1)
   {  
       PlaySoundAtEntity("PlaySound", "Sound.snt", "Player", 0.0f, true);
   }

   else if(alState == -1)
   {  
       StopSound("PlaySound", 0.0f);
   }
}

This way, you can always be absolutely certain that ONLY PlaySoundAtEntity OR StopSound will be executed, never both.

Again, not so important right now but I thought it might help you out in the future Tongue

(This post was last modified: 06-18-2013, 06:47 PM by Adrianis.)
06-18-2013, 06:44 PM
Find


Messages In This Thread
sound playing in area - by 39Games - 06-16-2013, 10:30 AM
RE: sound playing in area - by PutraenusAlivius - 06-16-2013, 10:45 AM
RE: sound playing in area - by 39Games - 06-16-2013, 10:52 AM
RE: sound playing in area - by PutraenusAlivius - 06-16-2013, 10:59 AM
RE: sound playing in area - by 39Games - 06-16-2013, 11:06 AM
RE: sound playing in area - by ExpectedIdentifier - 06-16-2013, 11:11 AM
RE: sound playing in area - by 39Games - 06-16-2013, 11:26 AM
RE: sound playing in area - by Adrianis - 06-18-2013, 06:44 PM



Users browsing this thread: 1 Guest(s)