Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: PeteRenton on Sat 26/06/2004 15:23:26

Title: cycling through music
Post by: PeteRenton on Sat 26/06/2004 15:23:26
so for example, midid track 1 finishes, make it go onto track 2 instead of repeating track 2
Title: Re: cycling through music
Post by: strazer on Sat 26/06/2004 15:37:07
You can use the
  PlayMusicQueued (int music_number)
function:

Put your music files in the game folder (not compiled) and name them
music1.mid
music2.mid
music3.mid
and so on (if you use digital music, name them music1.mp3 etc. accordingly).

Then, go to the room you want these files to be played in.
Click the "i" (interaction) button.
Double-click on "Player enters screen (before fadein)".
Choose "Run script".
Click the "Edit script" button.
Write the following:

PlayMusic(1); // plays music1
PlayMusicQueued(2); // plays music2 when music1 has finished
PlayMusicQueued(3); // plays music3 when music2 has finished
//and so on

If you want the music to be played at game start, put these line in the "game_start" function of the global script.

Edit2:

Better yet, put this in the global repeatedly_execute function (Menu "Script" -> "repeatedly_execute"):

if (IsChannelPlaying(0) == 0) { // no music playing currently
  PlayMusic(1); // play music1
  PlayMusicQueued(2); // play music2 when music1 has finished
  PlayMusicQueued(3); // play music3 when music2 has finished
  //and so on
}

This way, the music doesn't stop when the last track finished playing.