Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: pier on Tue 12/05/2020 16:21:28

Title: [solved] wish that every room has its own music. But script doesn't work
Post by: pier on Tue 12/05/2020 16:21:28
Hello! I apologize if my question is stupid. But really i'm a noob at scripting, i tried to read in the manual but i can't solve it.
Fell free to insult me, i'm new with AGS  :smiley:
i Wanted the music to change every time you get to a different room, so using a specific music for each room, but the game only plays the first one for the starting room in each of them.
This are the scripts i made:

script for music 1 for the starting room
Code (ags*) Select

function roomAfterFadeIn()
{

  aMusic1.PlayFrom(1000);
  if (aMusic1.IsAvailable)
{
  aMusic1.Play();
}

  }


script for room2 and its own music. Here the music remains music 1 and nothing changes
Code (ags*) Select

function roomAfterFadeIn()
{
  aMusic1.Stop();
  aMusic3.PlayFrom(1000);
  if (aMusic3.IsAvailable)
{
  aMusic3.Play();
}

  }


thank you very much! :smiley:
Title: Re: wish that every room has its own music. But script doesn't work
Post by: Cassiebsg on Tue 12/05/2020 16:45:21
You can't just copy/paste into the scripts, you need to open the room, click on events and then click on the "room after fade in" to create a link to the code.  ;)
Title: Re: wish that every room has its own music. But script doesn't work
Post by: Crimson Wizard on Tue 12/05/2020 17:36:28
I'd like to point out that if you reserve strictly 1 channel for Music audio type in the editor (I think this is done by default), then you do not have to command "music.Stop", it will be replaced by new music automatically.
Title: Re: wish that every room has its own music. But script doesn't work
Post by: Khris on Tue 12/05/2020 17:37:51
You don't need the IsAvailable check, and you really don't need to play it twice.

In each room, add the "before fadein" event, this will create and link the  room_Load  function. In that function, simply add

Code (ags) Select
  aMusic1.Play();

If you have properly imported the audio files into the Music folder, playing a new audio file will stop the currently playing one (since there's only one available channel by default).
Title: Re: wish that every room has its own music. But script doesn't work
Post by: pier on Wed 13/05/2020 15:15:19
thank you very much to everybody! it worked!  :smiley: