Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Tue 09/04/2013 08:43:00

Title: SOLVED: Countdown audio and text
Post by: Slasher on Tue 09/04/2013 08:43:00
Hi

I'm trying to figure out a way how to play an audio countdown when a Timer Expires.

A NPC text displays a countdown every time Timer Expires (SayBackground)and works as it should (20 to 0).

I have tried different ways to approach this.

Maybe there is a way to PAUSE a sound (countdown audio 20-0)when Timer has Expired (Timer gets set again) and then UNPAUSE the sound or increment?

I have this so far in Timer Expired:

Code (AGS) Select
function room_RepExec()
{
if (IsTimerExpired(1))
{
  oblood.Move(oblood.X-0, oblood.Y+6, 2, eNoBlock, eAnywhere);
  countdown=(countdown-1);
  oghost3.SetView(81);
  oghost3.Animate(0, 4, eRepeat, eNoBlock);
  ccount.SayBackground(String.Format("%d",countdown)); // This is where have an audio countdown would come in.
  SetTimer(1, 40);
}


Is there a way to do this only it seems odd without audio whilst NPC is counting down, not blocked?

EDIT: I was thinking of doing something with the countdown int. It's set at 20 and lowers 1 each time Timer Expires.

EDIT EDIT: This seems to work ok and does not block or interfere with Timer events:

Code (AGS) Select
}
// COUNTDOWN AUDIO SOUND

if (countdown ==19 && Game.DoOnceOnly("19") && tasandun==false)
{
aCountdown19.Play();
}
if (countdown ==18 && Game.DoOnceOnly("18") && tasandun==false)
{
aCountdown18.Play();
}
if (countdown ==17 && Game.DoOnceOnly("17") && tasandun==false)
{
aCountdown17.Play();
}
if (countdown ==16 && Game.DoOnceOnly("16") && tasandun==false)
{
aCountdown16.Play();
}
if (countdown ==15 && Game.DoOnceOnly("15") && tasandun==false)
{
aCountdown15.Play();
}
if (countdown ==14 && Game.DoOnceOnly("14") && tasandun==false)
{
aCountdown14.Play();
}
if (countdown ==13 && Game.DoOnceOnly("13") && tasandun==false)
{
aCountdown13.Play();
}
//etc etc etc


This code has been if else slightly amended and in rep always so it works through blocks.

cheers

slasher


Title: Re: SOLVED: Countdown audio and text
Post by: Khris on Tue 09/04/2013 12:23:04
You can do the tasandun == false check like this:
Code (ags) Select
  if (tasandun == false) {
    ... play sounds
  }


Also, not sure you need all those Game.DoOnceOnly()s there; if the variable countdown is set to each value only once, that'll suffice.

It's really unfortunate that currently, sounds aren't numbered (like objects or views) and doing it like that or using an array whose values have to be assigned equally tediously is the only way.
Title: Re: SOLVED: Countdown audio and text
Post by: Slasher on Tue 09/04/2013 13:41:46
Khris

QuoteAlso, not sure you need all those Game.DoOnceOnly()s there
Yes, of course. Now that I have it working I could take the Game.DoOnce(s) Only out.

QuoteIt's really unfortunate that currently, sounds aren't numbered (like objects or views) and doing it like that or using an array whose values have to be assigned equally tediously is the only way.
It can be a tedious but such is life and I'm sure a later version will deal with this (laugh)

cheers

slasher