Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HandsFree on Fri 28/10/2011 21:43:25

Title: Ambient sound doesn't play [solved]
Post by: HandsFree on Fri 28/10/2011 21:43:25
In room_AfterFadeIn() for room 21 I have:
if ((cLan.PreviousRoom == 19) || (cLan.PreviousRoom == 36) || (cLan.PreviousRoom == 8 )) aNight.Play();

The soundfile only plays if the previous room was 36, but not coming from 19 or 8.
The only difference I can think of is that room 36 also has an ambient sound file playing (and 19 and 8 are silent).

In room 36 I have:
if ((cLan.PreviousRoom == 21) || (cLan.PreviousRoom == 34)) aCrickets.Play();
And that gives no problems.

Any ideas why aNight only plays when coming from room 36?
This is version 3.2.1.
Title: Re: Ambient sound doesn't play
Post by: steptoe on Fri 28/10/2011 22:22:40

Can the player go to room 21 from rooms 18,36 and 8?

if not than it will not work because only 1 room was Previous.

Or maybe you should use if the player Has Been in Room?

I assume I am on the right line with your query???






Title: Re: Ambient sound doesn't play
Post by: HandsFree on Fri 28/10/2011 22:41:33
Yes, you can go to room 21 from those rooms.
When you're on the townsquare (21) there is ambient sound -aNight- initially. You can enter the officebuiding ( 8 ) and the sound stops as scripted. When you then leave the office you're on the square (21) again but the sound doesn't start.

The same thing happens if you leave the square to enter the bar (19). But if you go to room 36 and come back aNight starts playing.

edit: to clarify: I always want the soundclip to play in room 21 and it stops when you leave the room.
BUT, when you are in room 21 and you look at one of the documents/letters you have, the game technically takes you to another room with the closeup. In that case the sounds does not stop and therefore it should not restart when returning to room 21.
Title: Re: Ambient sound doesn't play
Post by: Shane 'ProgZmax' Stevens on Sat 29/10/2011 01:25:38
okay, so in the Enters Room Before Fadein section, play the sound looping, and in the Leaves Room section stop the sound.
Title: Re: Ambient sound doesn't play
Post by: HandsFree on Sun 30/10/2011 00:12:59
Sorry, it still gives the same problem: the sound starts if the previous room was 36, but not if it was 8 or 19.
This really has me stumped.
Title: Re: Ambient sound doesn't play
Post by: Khris on Sun 30/10/2011 11:07:51
Dumb question maybe:
Is cLan the player?

What happens if you put
Display("%d", cLan.PreviousRoom);
in after fadein and go from say 19 to 21?
Title: Re: Ambient sound doesn't play
Post by: HandsFree on Sun 30/10/2011 11:29:25
Yes, cLan is the player.
And this is really weird, because coming from room 19 the display says "3", and coming from room 8 the display also says "3", but coming from 36 is says "36". How is this possible?

I tried to work around this BTW by coding:
if (NightSound == null) NightSound = aNight.Play();Which is a better way of dealing with this anyway, but now the sound only plays the first time you enter room 21.
To stop the sound I coded:
aNight.Stop();
Should I put NightSound somewhere in that statement too?

But I still like to know why the game thinks the previous room is 3 when it's 8 or 19.

edit: found the problem. leaving room 8 and 19 first sends you to room 3 and in before fadein it checks if it should be 21.

So my question is now:
I set the sound playing:
if (NightSound == null) NightSound = aNight.Play();
How do I stop the sound, using the NightSound variable?
If I just use aNight.Stop(); the condition "if (NightSound == null)" doesn't become true.
Title: Re: Ambient sound doesn't play
Post by: Khris on Sun 30/10/2011 16:44:16
Proper use would be
  Nightsound.Stop();
Calling aNight.Stop() works but stops all instances.

Then do
  if (!NightSound.IsPlaying) NightSound = aNight.Play();
Title: Re: Ambient sound doesn't play
Post by: HandsFree on Sun 30/10/2011 17:01:27
OK, now I have "if (!NightSound.IsPlaying) NightSound = aNight.Play();"
but the first time I enter room 21 I get the error "Null pointer referenced"
Should I initialize NightSound somewhere? The global variables editor doesn't give that option for audio channels.
Title: Re: Ambient sound doesn't play
Post by: Khris on Sun 30/10/2011 17:18:13
Try this:

if (NightSound == null || !NightSound.IsPlaying) NightSound = aNight.Play();

I assume you already have
AudioChannel*Nightsound;
in your room script, right?
Title: Re: Ambient sound doesn't play
Post by: HandsFree on Sun 30/10/2011 17:44:12
Quote from: LeKhris on Sun 30/10/2011 17:18:13
I assume you already have
AudioChannel*Nightsound;
in your room script, right?
No, I entered that in the global variables editor. Is that wrong?
Title: Re: Ambient sound doesn't play
Post by: Khris on Sun 30/10/2011 17:50:42
No, it's fine. I didn't realize the Global variables pane supports Pointers now.
Does it work now?
Title: Re: Ambient sound doesn't play [solved]
Post by: HandsFree on Sun 30/10/2011 21:19:16
Yes, if (NightSound == null || !NightSound.IsPlaying) NightSound = aNight.Play(); does the trick.

thanks.