Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Squinky on Wed 24/12/2003 22:06:53

Title: Going between sound and music?
Post by: Squinky on Wed 24/12/2003 22:06:53
Okay, so I'd like to have an area where it plays an soundeffect like wind or something for a while and then everynow and then would play my midi track, and then go through the cycle again....

I think 5 days a stranger had this, where it would play creepy stuff and then go into the music...

Anybody know how to do that?


Edit-----

Heres my first try, it just makes weird noises instead of playing either...I tried adding a (IsSoundPlaying()==0) to the is music playing part, but it still did the same thing...

It sounds like it's trying to start the sound over and over...


Player enters screen:

PlayAmbientSound (1,1,50,0,0);
SetTimer (1,100);


rep exec
if (IsTimerExpired (1)==1){
 PlayMusic (1);
 }
if (IsMusicPlaying ()==0){
 PlayAmbientSound (1,1,50,0,0);
 SetTimer (1,1000);
 }
Title: Re:Going between sound and music?
Post by: Pumaman on Wed 24/12/2003 23:02:48
What's happening is that it is constantly re-starting the ambient sound, which is why you hear a strange noise.

This script:

if (IsMusicPlaying ()==0){
PlayAmbientSound (1,1,50,0,0);
SetTimer (1,1000);
}

keeps executing (since the music hasn't started playing yet) and re-starting the sound and the timer.

You need another variable to keep track of whether you've already started the sound playing or not.
Title: Re:Going between sound and music?
Post by: Squinky on Thu 25/12/2003 04:06:36
A-ha! That did it, thank you.

Now onto the new issues:

You enter the room, it plays the sound until the conditions are met to play the music...then it just keeps playing the music...

Is there any way to stop music from looping once it's started? I figure it either that or my variable/timer is goofy...


 // script for room: Repeatedly execute
//-----music + sound-------------
if (IsTimerExpired (1)==1){
 PlayMusic (1);
 SetTimer (1,500);
 StopAmbientSound (1);
 SetGlobalInt (1,0);
 }
if ((IsMusicPlaying ()==0)&&(GetGlobalInt (1)==0)){
 PlayAmbientSound (1,1,50,0,0);
 StopMusic ();
 SetTimer (1,500);
 SetGlobalInt (1,1);
 }
Title: Re:Going between sound and music?
Post by: Scorpiorus on Fri 26/12/2003 21:56:45
QuoteIs there any way to stop music from looping once it's started?
Take a look at the SetMusicRepeat() function in the manual. Is it what you need?

Just place it before calling PlayMusic():

SetMusicRepeat(0);
PlayMusic(...);
Title: Re:Going between sound and music?
Post by: Squinky on Fri 26/12/2003 22:40:59
Yes, Excellent. That did it for me...