setTimerOn problem
by johnson518 · in Torque Game Builder · 08/28/2009 (1:26 am) · 2 replies
Hi, I want to decrease the mobile's energy by one in every second., so here is my code. but it seems that the onTimer is never called to function. as if onTimer is called then the mobile will change the moving direction. By the way, the mobile has got some object mounted to it.
function Auto::attach(%this, %src)
{
$mobile=%this;
$Energy=5;
%src.mount($mobile,0,0,0,true,true,false,true);
%this.setLinearVelocityX(1);
%this.setTimerOn(1000);
}
function Auto::OnTimer(%this)
{
$Energy=$Energy-1;
if($Energy<=0)
{
%this.setTimerOff();
%this.safeDelete( );
return;
}
%dir=$Energy*10;
%this.setLinearVelocityPolar(%dir, 3);
}
function Auto::attach(%this, %src)
{
$mobile=%this;
$Energy=5;
%src.mount($mobile,0,0,0,true,true,false,true);
%this.setLinearVelocityX(1);
%this.setTimerOn(1000);
}
function Auto::OnTimer(%this)
{
$Energy=$Energy-1;
if($Energy<=0)
{
%this.setTimerOff();
%this.safeDelete( );
return;
}
%dir=$Energy*10;
%this.setLinearVelocityPolar(%dir, 3);
}
#2
08/29/2009 (12:03 am)
HI, thank you for your reply, but even after i corrected it, it still does not work. and I think toque script is not case sensitive. so maybe i need to check whether it is the issue of collision handling. As when %src object is mounted to $mobile object, it may cause onCollision for %src object to be called all the time.
Torque Owner RollerJesus
Dream. Build. Repeat.
I don't see anything off the bat that would make this not work. Have you tried putting an echo statement in your onTimer() (I think this should be lowercase... could be the issue) callback to see if it's getting fired?
Try something like this.
function Auto::attach(%this, %src) { $mobile=%this; $Energy=5; %src.mount($mobile,0,0,0,true,true,false,true); %this.setLinearVelocityX(1); %this.setTimerOn(1000); } function Auto::onTimer(%this) { echo("OnTimer callback fired."); $Energy=$Energy-1; if($Energy<=0) { %this.setTimerOff(); %this.safeDelete( ); return; } %dir=$Energy*10; %this.setLinearVelocityPolar(%dir, 3); }