How to use Audioclip from the Globalvariables

Started by AndreasBlack, Thu 13/10/2022 09:46:49

Previous topic - Next topic

AndreasBlack

I want to be able to automate it's volume (I'm thinking this is a specific audioclip, not sure if that is what "audioclip" really is, tho"). Audio should be able to go in or out volume wise and stop, if that's possible. See i'm ringing a doorbell in the game, say the player skips the cutscene. What happens is the sound keeps on ringing, and rings into the nextime he (if) he rings the bell again really fast afterwards, probably nobody will do that, but still. That would be no problem if i could easily fade out and stop the sound, i don't want to just call aSoundplay.Stop(); that sounds horrible with a click ending. But i have no idea how to do it. Tween module doesn't seem to have any options for it unless i'm blind. I also wonder if it's possible to apply that to a vieweditor framesound that's playing? If i set the sound in use as a global audioclip would i then be able to say not play the sound again if it's already playing from the vieweditors frame? Sorta like a repeatedly execute function that detects if it's playing from the vieweditors/frame?

Thanks



AndreasBlack


Khris

Create a global AudioChannel pointer:

Code: ags
// global header
import AudioChannel* cutSceneAudio;

// top of global script
AudioChannel* cutSceneAudio;
export cutSceneAudio;

In your cutscene, only play the clip if the player hasn't already skipped it:
Code: ags
  if (!Game.SkippingCutscene) cutSceneAudio = aDoorbell.Play();

When ending the cutscene, fade out the clip:
Code: ags
  if (EndCutscene() && cutSceneAudio.isPlaying) {
    for (int vol = 95; vol >= 0; vol -= 5) {
      cutSceneAudio.Volume = vol;
      Wait(2); // 1 second fade to silence at default game speed
    }
  }

AndreasBlack

Ahh, Thanks as always, Khris! Will check that out. Hopefully now i can try to solve the issue with the vieweditor sounds playing over each other aswell.

AndreasBlack

Soooo, i'm still running into trouble. I hope AGS 3.6 solves all these issues for me. ;)   :-D

I've tried to set an audioclip to 0 from the getgo in the project explorer >-- audio window >-- Default Volume = 0. So i guess when it plays (if it plays if it's at 0, i think it should, correct?). Audioclip is used by the global audiochannel Ruben_BG_Sounds.

Now when i walk on my region 11 i try to do this, but unfortunaly, it just won't work as i want it too!

Code: ags
function region11_WalksOnto()
{
  
  if (Ruben_BG_Sounds!=null)
  
  {
     
if (Ruben_BG_Sounds.IsPlaying)

{
  
  Ruben_BG_Sounds.TweenVolume(0.3, 100, eEaseLinearTween, eNoBlockTween); //this works if sound is set it's basic default volume setting 
 
  Ruben_BG_Sounds.Volume=100; //Trying this and commenting out tweenvolume, doesn't work either. i'm really confused. It seems like volume 0 is untouchable.
                               //but for unknown reason you can hear when the tweenvolume changes happen, but then it goes back to 0, again!?  


}
    
     
}

}


eri0o

Try using rep exec or rep exec always depending of your expectation of how it should work and handle getting the current region and state change from one region to the other yourself. The region is an event, but if a blocking action happens, the blocking will prevent the event - say the character walks and talks to someone, and during this walking it switches region. If you are handling this yourself, you can use rep exec always to make sure the "event" happens when you are expecting it to.

Also if you tween with nonblock, it will go right to the next line - can't really tell which one will matter later.

In 3.6 if you play and set the volume later in the same frame, it's alright, it won't actually play until the frame has ended, so whatever it was the volume set at the start of the frame what matters is the one at the end.

AndreasBlack

#6
Thanks for replying! There's a walkingpath NPC character going around with non-blocking in bakground, it's e-blocking for a microsecond but there's no sound playing there at all. I will probably go over that entire code later it wasn't long ago when i was extremely bad at coding, but most of is indeed none-blocking, and then eventually he does an animation which is also none blocking. Oh i forgot there's a function in room_load, that makes this walkingpath work, nothing in repeat or always repeat. Edit: Doh, i think i've solved it myself. Ofc it doesn't matter which side i walk off the region from, then it will fade out, since i have a fade out function, i should probably put the fadeout function on another region instead, that will probably solve it, i hope! Edit 3: Nope, did not work. Well Beeepp this..I'll do other more important things.

Code: ags
  
	

  
  if (cRuben.x == 6376 && !cRuben.Moving)  
     
{ 



   
	cRuben.Animate(9, 2, eOnce, eNoBlock);
	Ruben_BG_Sounds = aDrill.Play();                  //The theory is as follows. volume-default 0 = means the sound will play once (correct?), 
                                                     //and the channel should then recognise ok, this sound is part of Ruben_BG_Sounds
                                                     //so why it won't let me raise the volume of the clip to 100% is beyond me..shouldn't it work?
                                                     //i mean obviously since tween module recognises the regions then i don't see how this is an issue?
  

 
}


AndreasBlack

Quote from: hiroka on Sun 23/10/2022 21:12:32I'm glad somebody has the same problem that I had trouble with, so thank you for the answers.

Glad it could help! Btw, i've solved my issue by having the NPC start walking/animating ones my character reached the same region spot that is tweening the sound effects of the NPC! So that was a solution that works when 0 volume in the editor obviously don't, for unknown reason.

SMF spam blocked by CleanTalk