Problem with schedule
by Laralyn McWilliams · in Torque Game Builder · 04/08/2010 (1:29 pm) · 4 replies
I'm working with the fadeOut script from the resources. When I use these bits of code, the item fades out correctly over a couple seconds:
Yet when I try to do the same thing by passing a parameter to the functions to replace that hard-coded "50," the text fades way too quickly.
Trial and error shows me that it doesn't matter what I do with a parameter or the number 50 in startFadeOut()--the setting in the fadeOut() function is the one used. What I don't understand is why I can't pass in a parameter set to 50 like in the second example, and have it work... because whether it's hard-coded or from that parameter, the fadeOut function should be getting the number 50.
Can anyone help? Thanks!
criticalAlert.startFadeOut();
...
function t2dSceneObject::startFadeOut(%this)
{
%this.setBlendAlpha(1.0);
%this.schedule(50, fadeOut);
}
function t2dSceneObject::fadeOut(%this)
{
// Fetch the current alpha value
%alpha = %this.getBlendAlpha();
// Decrease it
%alpha -= 0.01;
if(%alpha < 0)
{
}
else
{
%this.setBlendAlpha( %alpha );
%this.schedule(50, fadeOut);
}
}Yet when I try to do the same thing by passing a parameter to the functions to replace that hard-coded "50," the text fades way too quickly.
criticalAlert.startFadeOut(50);
...
function t2dSceneObject::startFadeOut(%this, %lengthOfFade)
{
%this.setBlendAlpha(1.0);
%this.schedule(%lengthOfFade, fadeOut);
}
function t2dSceneObject::fadeOut(%this, %lengthOfFadeOut)
{
// Fetch the current alpha value
%alpha = %this.getBlendAlpha();
// Decrease it
%alpha -= 0.01;
if(%alpha < 0)
{
}
else
{
%this.setBlendAlpha( %alpha );
%this.schedule(%lengthOfFadeOut, fadeOut);
}
}Trial and error shows me that it doesn't matter what I do with a parameter or the number 50 in startFadeOut()--the setting in the fadeOut() function is the one used. What I don't understand is why I can't pass in a parameter set to 50 like in the second example, and have it work... because whether it's hard-coded or from that parameter, the fadeOut function should be getting the number 50.
Can anyone help? Thanks!
#2
and
If you don't do this then the parameter is not passed to the fadeout() method.
04/08/2010 (1:43 pm)
Just took a quick glance, but I think you need to add your %lengthOfFadeOut parameter to your schedule calls:%this.schedule(%lengthOfFade, fadeOut,%lengthOfFade);
and
%this.schedule(%lengthOfFadeOut, fadeOut,%lengthOfFadeOut);
If you don't do this then the parameter is not passed to the fadeout() method.
#3
Edit: Looks like Kenneth beat me to it.
04/08/2010 (1:46 pm)
I think your problem is that on lines 8 and 25 you aren't passing the %lengthOfFadeOut when you schedule fadeOut. So when fadeOut schedules itself again, it is scheduling for zero milliseconds, which would make it quick. You can pass an argument to a scheduled method like this:%this.schedule(%lengthOfFade, fadeOut, %lengthOfFade);
Edit: Looks like Kenneth beat me to it.
#4
In case it helps anyone else doing a search for schedule help, here is the code that works:
04/08/2010 (1:53 pm)
You were both right--thank you!In case it helps anyone else doing a search for schedule help, here is the code that works:
criticalAlert.startFadeOut(%this, 50);
...
function t2dSceneObject::startFadeOut(%this, %lengthOfFade)
{
%this.setBlendAlpha(1.0);
%this.schedule(%lengthOfFade, fadeOut, %lengthOfFade);
}
function t2dSceneObject::fadeOut(%this, %lengthOfFadeOut)
{
// Fetch the current alpha value
%alpha = %this.getBlendAlpha();
// Decrease it
%alpha -= 0.01;
if(%alpha < 0)
{
}
else
{
%this.setBlendAlpha( %alpha );
%this.schedule(%lengthOfFadeOut, fadeOut, %lengthOfFadeOut);
}
}
Torque Owner RollerJesus
Dream. Build. Repeat.
criticalAlert.startFadeOut(%this, 50);