[solved] wish that every room has its own music. But script doesn't work

Started by pier, Tue 12/05/2020 16:21:28

Previous topic - Next topic

pier

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*

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*

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

  }


thank you very much! :smiley:

Cassiebsg

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.  ;)
There are those who believe that life here began out there...

Crimson Wizard

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.

Khris

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
  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).

pier


SMF spam blocked by CleanTalk