Game Development Community

Freezing function

by D B · in Torque Game Engine · 03/19/2006 (3:30 pm) · 3 replies

I have made a function that is supposed to fade music when called (I plan to use it with Robert Geiman's VMPlayer). However, I can't seem to accurately test it, as it freezes the game whenever I call it. This is the function:

function FadeMusic(%t)
{
echo("FadeMusic called");
for (int i = 1; i < (%t * 10); i++)
{
schedule(100,0,$VMPlayer.SetVolume -= (1 / (%t * 10)));
echo("Schedule " + i + " done");
}
StopMusic();
echo("Music stopped");
}

%t is supposed to be the time in seconds it takes to fade out the music, and $VMPlayer.SetVolume sets the volume anywhere between 0.0 and 1.0 (as per the VMPlayer resource).

However, it freezes straightaway when called, and even the first thing (echo("FadeMusic called");) does not appear. Is it something to do with %t? I'm unsure of how to fix this.

Thank you.

#1
03/19/2006 (10:31 pm)
function FadeMusic(%t)
{
    echo("FadeMusic called");

    for (%i = 1; %i < (%t * 10); %i++)
   {
        $VMPlayer.schedule(100, SetVolume, (1 / (%t * 10)));
        echo("Schedule " @ %i @ " done");

   }
   schedule(%t * 10, 0, StopMusic);
}



function StopMusic()
{
     echo("Music stopped");

     $VMPlayer.SetVolume(0);
}


That's probably not going to work exactly as you desire, but it should stop your lockups
#2
03/20/2006 (5:00 pm)
Ah, thank you, Gonzo! It doesn't freeze and I've got it working very nicely now. :D
#3
03/20/2006 (8:04 pm)
Your Welcome

Glad you got it all fixed up.