Music ends

Posted By: Ruben

Music ends - 03/19/16 07:45

I have a medieval soldier that is climbing spiral stairs in a tower. If the player gets up to a certain height (z level), the game takes control of the player, and moves it along a certain path up the stairs, and then rotates the player to view something that the game wants the player to view.

When this happens, I am trying to make a different song play, so that the player knows something different is going on, and that it is not a bug. I have it so that the new song plays, however, after the player automatically moves to the new position, and finishes rotating to view whatever the game wanted it to view, the music abruptly stops after the rotation.

This is the code I have for this so far:

Code:
...

wizardEnemy_action()
{
   ...

   while(1)
   {
      ...

      c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | 
         SCAN_FLAG2 | IGNORE_ME);
				
      if (you) // player detected?
      { 
         if((you.z >= 2397) && (you.z < 2500))
         {
            snd_stop ( songHandle);

	    songHandle = snd_loop(sndWizMusic, 100, 0);	

            // sndWizMusic loop starts playing.
	
	    ent_moveto(hero, vector(-179, 581, 2458), 5);
	    wait_for_my(ent_moveto);
		
            ent_turnto(hero,vector(-59,0,0),5);
	    wait_for_my(ent_turnto);

            // sndWizMusic loop stops here for some reason,
            //    after player's rotation is complete.

            ...
         }

         ...

      }
      wait(1);
   }
}



Does the ent_turnto function somehow make the sound stop playing? If so, is there a way around it?
Posted By: Ruben

Re: Music ends - 03/19/16 10:09

I notice that when I put this code:

Code:
...

snd_stop ( songHandle);

songHandle = snd_loop(sndWizMusic, 100, 0);

...



before this code:

Code:
c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);



The music starts before the player reaches z = 2397 , but the music lasts even after the player is automatically moved and rotated.
Posted By: EpsiloN

Re: Music ends - 03/24/16 22:34

Its hard to say what is causing this, because you're showing only a part of the action.

The if conditions might become false after you move the player to his new position, and the whole function stops until you move and turn the player and then continues, possibly hitting some other snd stop instruction...

This conclusion comes from the fact that moving snd_stop out of the if conditions plays the music before he reaches the desired height and after the turning took place...

I hope this helps laugh

EDIT*:
You could try renaming your snd handle to something else, for example eventMusicHandle, this way it wont be stopped, until it finishes, because no other snd_stop instruction with that handle exists...
Posted By: Reconnoiter

Re: Music ends - 03/25/16 10:56

What I find confusing about your code is that it happens all in a while loop; I would move some of it to a new function and call that instead (with an if() before it ofcourse) to make the code cleaner and to see the bugs faster.

Also this action is named wizardEnemy_action yet you describe it is about the player, is wizardEnemy_action a spelling/c&p mistake or does the player get moved by the enemy? (if so, than that sounds confusing too)
Posted By: Ruben

Re: Music ends - 03/27/16 07:48

Originally Posted By: EpsiloN
Its hard to say what is causing this, because you're showing only a part of the action.

The if conditions might become false after you move the player to his new position, and the whole function stops until you move and turn the player and then continues, possibly hitting some other snd stop instruction...

This conclusion comes from the fact that moving snd_stop out of the if conditions plays the music before he reaches the desired height and after the turning took place...

I hope this helps laugh

EDIT*:
You could try renaming your snd handle to something else, for example eventMusicHandle, this way it wont be stopped, until it finishes, because no other snd_stop instruction with that handle exists...

I tried your advice, and used a totally different song handle. Now, the song is lasting a little longer after the rotation is complete, but then it fizzles out, and I hear this little sound that seems to repeat really quickly, like maybe the beginning of the song trying to start once every quarter of a second.
Posted By: EpsiloN

Re: Music ends - 03/28/16 11:57

To eliminate the possibility that the song is trying to start over and over again, set the new handle to the song and play it only if the new handle is NULL. Otherwise, don't play anything.
After it stops, I cant remember if the handle becomes NULL by itself, or you have to set it somehow to NULL by hand.

This will play the full song over and over if its that sort of bug, not just the beginning...
© 2024 lite-C Forums