Thanks Jerrot for the great script!
May I make another suggestion?
I think that it could work with a GlobalMusicVolume too.
global music1;
global music2;
// Get the global music volume
global MusicVolume = Game.GetGlobalMusicVolume
function PlayMusicX(musicfile)
{
//---------------------------------------------------------------------
// Starts to play a musicfile. Uses a fading/crossover if another music
// is already playing.
//
// Syntax: PlayMusicX(musicfile)
// Sample: PlayMusicX("music\wintermutesong.ogg");
//---------------------------------------------------------------------
var old_channel, new_channel, counter;
// when entering a scene, we don't know, which channel entity is
// playing currently. so we have to check this here:
if (music1.IsSoundPlaying())
{
old_channel = music1;
new_channel = music2;
}
else if (music2.IsSoundPlaying())
{
old_channel = music2;
new_channel = music1;
}
else
{
// in case no music was playing (e.g. when starting the game) we just have
// to load the sound file into our channel entity and leave the function.
new_channel = music1;
new_channel.SetSoundVolume(MusicVolume);
new_channel.PlaySound(musicfile,true);
return;
}
// this is a very simple crossover. counting to "MusicVolume", the volume of the old_channel
// is decreased to zero, while the volume of the new_channel is increased to "MusicVolume".
// the Sleep(50) command sets the speed of the crossfading.
new_channel.SetSoundVolume(0);
new_channel.PlaySound(musicfile,true);
for(counter=1; counter<=MusicVolume; counter=counter+1)
{
old_channel.SetSoundVolume(MusicVolume-counter);
new_channel.SetSoundVolume(counter);
Sleep(50);
}
old_channel.StopSound();
// That's it! Enjoy!
return;
}
Ofcouse the game that is going to use this script must have a menu, so that the player can adjust the GlobalMusicVolume.
Mnemonic, does the SetGlobalMusicVolume adjusts the music volume in real time, or only after a restore? Is the volume saved in the registry or only in the saved games? The Game.GetGlobalMusicVolume reads the value from the registry or a saved game?