A Question About Music Continuity (coding)

Started by AuT, Fri 23/03/2018 00:24:10

Previous topic - Next topic

AuT

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


Room 2 (Jaw's Office) (aMusictrack001):
D3 leads back to "SP's Office" (Room 1)


Room 3 (World Map) (aWorldmaptheme001):
Clicking on the office building leads back to "SP's Office" (Room 1).


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

Code: ags

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

Gilbert

Just check in Room 1 what the previous room was, such as:
Code: ags

function room_Load()
{
  if (player.PreviousRoom != 2) aMusictrack001.Play();
}

AuT

oooh... thank you (laugh) I'll give that a shot. I really appreciate the help and response.


AuT

#4
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.

SMF spam blocked by CleanTalk