Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: AuT on Fri 23/03/2018 00:24:10

Title: A Question About Music Continuity (coding)
Post by: AuT on Fri 23/03/2018 00:24:10
TLDR: If entering Room 1 from Room 3 play aMusictrack001. If entering Room 1 from Room 2 continue playing aMusictrack001 (not restart playing aMusictrack001).

Hello,

I'm working on my first game in AGS. Here are the rooms in regards to the question I have about music continuity.

Room 1 (SP's Office) (aMusictrack001):
D1 leads to the "World Map" (Room 3). D2 leads to "Jaw's Office" (Room 2).
(https://i.imgur.com/AXAkSBk.jpg)

Room 2 (Jaw's Office) (aMusictrack001):
D3 leads back to "SP's Office" (Room 1)
(https://i.imgur.com/ZxlC2YQ.jpg)

Room 3 (World Map) (aWorldmaptheme001):
Clicking on the office building leads back to "SP's Office" (Room 1).
(https://i.imgur.com/EI629Df.jpg)

So here's my question. The starting room is Room 1 (SP's Office). To start the music (aMusictack001) I have:

Code (ags) Select

function room_Load()
{
  aMusictrack001.Play();
}


When the player goes to D2 to enter room 2 the music keeps playing. This is good. It doesn't restart, it just continues (because I don't have any code in Room 2 to start new music). However, going from Room 2 back to Room 1 the song restarts. I understand that it's because of the line of code I've included in Room 1. So, how can I have it just continue playing the song going from Room 2 back to Room 1? These two rooms are part of the same building, so I would like the music to stay continuous. When the player goes through D1 (which leads to the World Map), the track changes to aWorldmaptheme001 music. So when they enter back into the office, I would like aMusictrack001 to start playing.

TLDR: If entering Room 1 from Room 3 play aMusictrack001. If entering Room 1 from Room 2 continue playing aMusictrack001 (not restart playing aMusictrack001).
Title: Re: A Question About Music Continuity (coding)
Post by: Gilbert on Fri 23/03/2018 01:17:03
Just check in Room 1 what the previous room was, such as:
Code (ags) Select

function room_Load()
{
  if (player.PreviousRoom != 2) aMusictrack001.Play();
}
Title: Re: A Question About Music Continuity (coding)
Post by: AuT on Fri 23/03/2018 01:41:12
oooh... thank you (laugh) I'll give that a shot. I really appreciate the help and response.
Title: Re: A Question About Music Continuity (coding)
Post by: Khris on Fri 23/03/2018 07:40:38
Here's a solution that requires minimal work once implemented:

http://www.adventuregamestudio.co.uk/forums/index.php?topic=50363.msg636486911#msg636486911
Title: Re: A Question About Music Continuity (coding)
Post by: AuT on Fri 23/03/2018 22:39:39
Wow. Thank you Khris. I think that's exactly what I needed. Cheers.

I'm still learning to code (in AGS and in general), so seeing the different ways of approach is helping to make what I'm coding (usually copying) much less abstract.