Ambient sound doesn't play [solved]

Started by HandsFree, Fri 28/10/2011 21:43:25

Previous topic - Next topic

HandsFree

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.

steptoe


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???







HandsFree

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

Shane 'ProgZmax' Stevens

okay, so in the Enters Room Before Fadein section, play the sound looping, and in the Leaves Room section stop the sound.

HandsFree

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.

Khris

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?

HandsFree

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

Khris

Proper use would be
Code: ags
  Nightsound.Stop();

Calling aNight.Stop() works but stops all instances.

Then do
Code: ags
  if (!NightSound.IsPlaying) NightSound = aNight.Play();

HandsFree

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.

Khris

Try this:

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


I assume you already have
Code: ags
AudioChannel*Nightsound;

in your room script, right?

HandsFree

Quote from: LeKhris on Sun 30/10/2011 17:18:13
I assume you already have
Code: ags
AudioChannel*Nightsound;

in your room script, right?
No, I entered that in the global variables editor. Is that wrong?

Khris

No, it's fine. I didn't realize the Global variables pane supports Pointers now.
Does it work now?

HandsFree

Yes, if (NightSound == null || !NightSound.IsPlaying) NightSound = aNight.Play(); does the trick.

thanks.

SMF spam blocked by CleanTalk