Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HandsFree on Thu 29/03/2012 00:45:00

Title: Sound restarts at changeroom
Post by: HandsFree on Thu 29/03/2012 00:45:00
I have a few adjacent rooms that should have the same sounds playing.
In the room_load of each room I have:

  if (iHours < 20){
    if (Daysound == null || !Daysound.IsPlaying){
      Daysound = aBirds.Play();
    }
  }
  else{
    if (Daysound != null && Daysound.IsPlaying) Daysound.Stop();
    if (Nightsound == null || !Nightsound.IsPlaying) Nightsound = aNight.Play();
    if (Crickets == null || !Crickets.IsPlaying) Crickets = aCrickets2.Play();
  }

Now if I set iHours to 20 in the global variables pane this works fine. The sounds don't restart when I change rooms.

But If I set iHours to 19 and do some in-game things that set iHours to 20, then the sounds restart on every changeroom.
As if the (Nightsound == null || !Nightsound.IsPlaying) condition is true every time.

Any ideas why this happens?
thanks
Title: Re: Sound restarts at changeroom
Post by: Shane 'ProgZmax' Stevens on Thu 29/03/2012 03:26:56
Sounds like an order of execution issue.  Basically, your logic is probably setting the variable to some value outside of the room but it doesn't happen before the room transition occurs.  Try placing your logic in the Repeatedly_Execute_Always() function (you'll probably have to add it manually).  As long as you're just incrementing some variables, that function will check your logic every single loop.  If this does not remedy the issue then I recommend you post all your logic for altering the iHours variable in-game as there is likely a problem with something you did.

Title: Re: Sound restarts at changeroom
Post by: HandsFree on Thu 29/03/2012 12:17:53
I tracked down the order of execution problem to this bit:

    if (Daysound != null && Daysound.IsPlaying){
      Daysound.Stop();
    }
    if (Nightsound == null || !Nightsound.IsPlaying){
      Nightsound = aNight.Play();
    }
The nightsound and daysound are both ambient sounds of which only one can play at the time.
I solved it for now by setting the aNight soundtype to 'sound' instead of ambient sound.
Is there abetter way around this?