Wintermute Engine Forum

Wintermute Engine => Scripts, plugins, utilities, goodies => Topic started by: keybone on March 04, 2012, 12:26:02 PM

Title: Fade Music and question for method
Post by: keybone on March 04, 2012, 12:26:02 PM
Hi, i have create this simply script for fade in the music. This work ::beer


Code: WME Script
  1. Game.PlayMusicChannel(2,"path music");
  2.  
  3.  
  4. var volume ;
  5.   for (volume=volume; volume>1; volume=volume-1)
  6.                 {
  7.                 Game.SetMusicChannelVolume(2,volume);
  8.                 Game.Msg(volume);
  9.                 Sleep(100);
  10.                 }

i have a question for create a method for dont rewrite this code for any scene, how can done it?

i have try with this in the game.script
method MusicFade(Channel)
{
   var volume ;
   volume = Game.GetMusicChannelVolume(Channel);
   for (volume=volume; volume>1; volume=volume-1)
      {
      Game.SetMusicChannelVolume(Channel,volume);
      Game.Msg(volume);
      Sleep(100);
      }
}

and in the scene i have put code
Game.MusicFade(2);

but dont work  :'( 

any idea..?

p.s. game.msg is only for check..
Title: Re: Fade Music and question for method
Post by: Kaz on March 04, 2012, 07:35:09 PM
I'd suggest you use a separate variable for your loop to the one for your volume so you don't corrupt them. You can still use 'volume' as your seed. Try:
for(var loop = volume; loop > -1; loop = loop -1)
  {
  Game.SetMusicChannelVolume(2, loop);
  Sleep(100);
  }

Hope that helps
Title: Re: Fade Music and question for method
Post by: keybone on March 04, 2012, 08:47:14 PM
tk for info Kaz;)

i have work on the script and i have find finally  ::rock how use method for done fadeIn e FadeOut of the music.

first to all crate methods.inc

and put this code:

Code: WME Script
  1. method MusicFadeOut(Channel)
  2. {
  3.    var volume ;
  4.    volume = Game.GetMusicChannelVolume(Channel);
  5.    var loop;
  6.    Game.Msg(volume);
  7.    for (loop=volume; loop>1; loop=loop-1)
  8.                 {
  9.                 Game.SetMusicChannelVolume(Channel,loop);
  10.                 Game.Msg(loop);
  11.                 Sleep(100);
  12.                 }
  13. }
  14. //////////////////////////////
  15. //to increase the volume to the level that we want (VolumeMax)
  16. method MusicFadeIn(Channel, volumeMax)  //channel and volumeMax
  17. {
  18.    var volume ;
  19.    volume = Game.GetMusicChannelVolume(Channel);
  20.    var loop;
  21.    Game.Msg(volume);
  22.    for (loop=volume; loop<volumeMax; loop=loop+1)
  23.                 {
  24.                 Game.SetMusicChannelVolume(Channel,loop);
  25.                 Game.Msg(loop);
  26.                 Sleep(100);
  27.                 }
  28. }
  29.  

then in base.inc add in methods.inc

Code: WME Script
  1. #include "scripts\methods.inc"

for use the methods

FADEIN

Code: WME Script
  1. Game.PlayMusicChannel(2,"path muisc");
  2.  
  3. Game.MusicFadeIn(2,70);

in this way the volume increases to the maximum volume, in this case we decided that is 70.

FADE OUT

Code: WME Script
  1. Game.PlayMusicChannel(2,"path muisc");
  2. Game.MusicFadeIn(2);
  3.  

in this way diminish the volume gradually to 0.

of course remove Game.Msg. I am just to check if everything works.
I hope I can help someone. ::wave