Schedule issue (SOLVED)
by Richard Petrov · in Torque Game Builder · 10/17/2011 (11:45 am) · 2 replies
I'm using the standard aStarActor class and I'm wanting the aStarActor to attack a victim over and over again.
I figured once it reaches the destination ("We made it!") I would schedule an attack after 1 second which calls munchVictim. Then if the hitpoints don't = 0 I will call the munchVictim function again using the schedule command.
Problem I'm having is regardless of how much time I put for the schedule the damage goes from 100 to 1 in a second.
So this is the code for when the aStarActor reaches it's destination:
I figured once it reaches the destination ("We made it!") I would schedule an attack after 1 second which calls munchVictim. Then if the hitpoints don't = 0 I will call the munchVictim function again using the schedule command.
Problem I'm having is regardless of how much time I put for the schedule the damage goes from 100 to 1 in a second.
So this is the code for when the aStarActor reaches it's destination:
function aStarActor::onAStarDestinationReached(%this)
{
echo("We made it!");
schedule(1000,0, %this.munchVictim());
// stop moving
%this.setLinearVelocity("0 0");
// need to remove the path
if (isObject(%this.currentPath) )
{
%this.pathGrid.deletePathID(%this.currentPath);
}
if (isObject(%this.testingpath) )
{
%this.pathGrid.deletePathID(%this.testingPath);
}
%this.die("escaped");
}
function aStarActor::munchVictim(%this)
{
if ($victimHealth > 0) {
echo ("Victim's Health: ", $victimHealth);
$victimHealth = $victimHealth - 1;
schedule(5000,0, %this.munchVictim());
}
}About the author
#2
10/18/2011 (6:37 am)
Little changes make things work. :-P Thanks! I've always put them in quotes but I thought I was being clever doing it the other way.
Torque Owner Rpahut
Same thing - here munchVictim() keeps calling itself recursively until health reaches zero. Schedule itself probably does nothing, as no function name passed into it.
A proper way to schedule method of an object would be like this: