(Solved)Audio type is supposed to stop when key is pressed but it doesn't.

Started by FanOfHumor, Sat 01/01/2022 19:20:17

Previous topic - Next topic

FanOfHumor

I have this script here which doesn't want to skip the audio type when a key is pressed.
Code: ags

function repeatedly_execute_always()
{
  if(IsKeyPressed(eKeyEscape))
  {
    if(Game.IsAudioPlaying(eAudioTypetalk2))
    {
      Game.StopAudio(eAudioTypetalk2);
      lblAction.Text="";
    } 
  } 
}

Could I have done something wrong with  this custom say function that messes it up?
Code: ags

function MySay(this Character*, AudioClip *talk, String text)
{
  talk.Play();
  this.SayBackground(text);
}

eri0o

Why are you using repeatedly execute always instead of event handling?

Are you sure the imported clip is of the selected audio type? Are you sure your code inside the if is being reached? Can you place a breakpoint on the line of Game.StopAudio to check it's been run?

Crimson Wizard

I may confirm that this code works in a simple test game, so, as eri0o suggested, I'd first of all check if your clips actually have the correct audio type set.
Secondly, maybe double check how they are started, and if there's some code that quickly restarts them right after they were stopped.

On the other hand, the usual way to handle key presses is on_key_press function. Is there a reason why you are not using that, but IsKeyPressed in rep-exec-always?

FanOfHumor

I checked to see if its under the right type and it is.And I placed this into on key press.Im not sure what you mean by event handler.I dont see a function by that name in globalscript.I also placed something simple inside of this so that I could test if anything inside of this is read and it isnt being read.

    if(Game.IsAudioPlaying(eAudioTypetalk2))
    {
      Game.StopAudio(eAudioTypetalk2);
      lblAction.Text="";
      ShakeScreen(6);
    }

Crimson Wizard

Quote from: Pajama Sam on Sun 02/01/2022 00:56:28
I checked to see if its under the right type and it is.

How do you check this? Just in case, the audio type is set in the sound clip's property, or sound folder's property, but it is not the name of the sound folder.

Quote from: Pajama Sam on Sun 02/01/2022 00:56:28
And I placed this into on key press.Im not sure what you mean by event handler.I dont see a function by that name in globalscript.

"event handler" is a function that is called on some event. on_key_press is one of the possible event handlers. It is added by hand (some game templates already have it in global script).
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html

FanOfHumor

Something must be wrong with the sound type that I made because after using a different type in the script it worked.Could you try to find out whats wrong with the sound type.Here is the game
https://www.mediafire.com/file/00qgxweicquzs4n/OceanBound.7z/file

Crimson Wizard

Quote from: Pajama Sam on Sun 02/01/2022 03:50:39
Something must be wrong with the sound type that I made because after using a different type in the script it worked.Could you try to find out whats wrong with the sound type.Here is the game
https://www.mediafire.com/file/00qgxweicquzs4n/OceanBound.7z/file

So, apparently there's both a mistake in game AND mistake in the engine.

In the game you reserve 8 channels for your sound types (Ambient: 1, Music: 1, Sound: 5, talk: 1), but engine only can give you 7 (because 1 is reserved for the speech). So you are trying to reserve 1 channel more than available.

However, there's some mistake in the engine, and it places your "talk" type sound on a special "hidden" channel which is normally used for some internal purposes (when crossfading tracks).
Both Game.IsAudioPlaying, and Game.StopAudio do not check that "hidden" channel because it's outside of normal channels. So they never detect and stop your sound.

The solution for now is to reduce one of the previous type, like, make Sound type to have 4 channels instead.

But the engine definitely has some bug that lets you force a sound onto the channel with index above 7, which also may lead to crashes if it's higher than 8. I could swear that I fixed this engine bug before, but maybe I fixed it in 3.6.0.
EDIT: right, it was fixed in 3.6.0. I might make another patch to 3.5.1, while 3.6.0 is still in works, as this is quite an annoying bug and may make it difficult to understand what's going on.

FanOfHumor

Im sure glad that you know what the problem is Crimson Wizard.For a while there I thought it might be one of those things that doesnt work for the longest time and then suddenly works for no known reason.But since you told me that its the engine Ill just either wait for that patch or use 3.6.0 when its stable.
Thanks for your help

SMF spam blocked by CleanTalk