Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: NiksterG on Thu 11/02/2010 19:36:54

Title: Getting Room load music
Post by: NiksterG on Thu 11/02/2010 19:36:54
Hi everyone,

I am returning to AGS after a few years break, and I am amazed at the changes that have happened. I think I can handle most of the bigger changes, but the new audio system is really getting me. I am trying to convert an old version 3.1.2 game to the new 3.2 RC3 version. I am going through all my scripts, and converting PlayMusic(#) to what they are supposed to be. However, there is one point where I coded this:

PlayMusic(Room.MusicOnLoad);

How would you convert this into the new version? Thanks in advance for the help!
Title: Re: Getting Room load music
Post by: Crimson Wizard on Thu 11/02/2010 19:52:44
AFAIK there's no such thing as Room.MusicOnLoad now. You should specify directly which music file you need to play at the room start, or elsewhen/where.
Check audio file names in the Audio subcategory on your project tree.

Syntax is like

aSomeMusic.Play();
Title: Re: Getting Room load music
Post by: NiksterG on Thu 11/02/2010 22:47:31
I understand the object oriented way of doing it, it's just that I need to know how to implement the Room.MusicOnLoad property if it doesn't exist anymore.

What I'm trying to accomplish is, the player enters the room, and music plays. Sometime while the player is in the room, he clicks on a menu, which opens different music. When the menu is closed, whatever music the room loads with starts over again. Depending on which room the player is in, this could be a different song - so I need the MusicOnLoad property.
Title: Re: Getting Room load music
Post by: Crimson Wizard on Thu 11/02/2010 23:12:06
Hmm, there's a point in this.

I have not much experience using new Audio system, but this is something that comes to mind (there may be better ways, perhaps):

You can use something like an AudioClip array to store room musics.
You will also need an AudioChannel to store menu music state.

AudioClip * RoomMusic[NUMBER_OF_ROOMS_YOU_HAVE];
AudioChannel * MenuMusicChannel;


You initialize array on game start, like:

RoomMusic[1] = aRoom1Music;
...


When menu music is launched you make this:

MenuMusicChannel = aMenuMusic.Play();


Then you can put this into global repeatedly_execute function:

if (MenuMusicChannel == null || !MenuMusicChannel.IsPlaying())
{
  RoomMusic[player.Room].Play();
}



EDIT: Oops, I forgot that room music will need a channel check too:


AudioChannel * RoomMusicChannel;



if ((MenuMusicChannel == null || !MenuMusicChannel.IsPlaying()) &&
     (RoomMusicChannel == null || !RoomMusicChannel.IsPlaying()))
{
   RoomMusicChannel = RoomMusic[player.Room].Play();
}