Issues with scheduling
by USC - IMD student 2 · in Torque Game Builder · 06/11/2008 (7:44 pm) · 2 replies
I got tired of banging my head on the keyboard and am asking for help. Sorry in advance if I've gone and done something stupid.
I have a boomerang-like object mounted on the player.
It needs to return to the player and remount if a certain amount of time (3 seconds, let's say) passes to prevent it from getting lost. If it collides with the player all on its own, it remounts and is ready to launch again. The timer should re-set and the next time it launches, 3 seconds again.
Here's what I did:
I have a function to launch the boomerang, sort of like this
function Boomerang ();
{
$boomerang.dismount();
$boomerang.SetLinearVelocity(%xcoord, %ycoord);
$returnEvent = schedule(3000, 0, "returnToMe");
}
and then the return function
function returnToMe();
{
echo ("return to me!");
%pos = $body.getPosition();
$boomerang.moveTo(%pos, 140, false, false, false, 1);
}
and in the OnCollision for the player object
if (isEventPending( $returnEvent ))
{
cancel( $returnEvent );
echo ("I'm canceling the event");
}
Here's the problem:
It's not canceling the scheduled return. If I get it back in 2 seconds and launch again, it immediately zips back after 1 second, not 3.
For some reason, it's doing two things I can't explain.
1) I see the "return to me!" debug printed between 4 and 10 times on a single throw in rapid succession.
2) It prints the cancel debug, but it doesn't seem to be actually canceling the event.
help? The documentation on schedules isn't helping. It just makes me want to burn everything down around me.
I have a boomerang-like object mounted on the player.
It needs to return to the player and remount if a certain amount of time (3 seconds, let's say) passes to prevent it from getting lost. If it collides with the player all on its own, it remounts and is ready to launch again. The timer should re-set and the next time it launches, 3 seconds again.
Here's what I did:
I have a function to launch the boomerang, sort of like this
function Boomerang ();
{
$boomerang.dismount();
$boomerang.SetLinearVelocity(%xcoord, %ycoord);
$returnEvent = schedule(3000, 0, "returnToMe");
}
and then the return function
function returnToMe();
{
echo ("return to me!");
%pos = $body.getPosition();
$boomerang.moveTo(%pos, 140, false, false, false, 1);
}
and in the OnCollision for the player object
if (isEventPending( $returnEvent ))
{
cancel( $returnEvent );
echo ("I'm canceling the event");
}
Here's the problem:
It's not canceling the scheduled return. If I get it back in 2 seconds and launch again, it immediately zips back after 1 second, not 3.
For some reason, it's doing two things I can't explain.
1) I see the "return to me!" debug printed between 4 and 10 times on a single throw in rapid succession.
2) It prints the cancel debug, but it doesn't seem to be actually canceling the event.
help? The documentation on schedules isn't helping. It just makes me want to burn everything down around me.
About the author
#2
I did like you suggested (my next step was going to be canceling the fire function if it had already fired anyway but this was a far more efficient solution.)
The ten or so extra echoes dried up right when I did it, and I was posting a bug that I couldn't get locked down but when checking the post for typos I found a stupid idiot mistake I made instead - now it works. I've edited the post to reflect that I'm happy -- hooray.
I have a feeling I may have another question later, but thanks!
06/12/2008 (3:32 pm)
That did make sense. Thanks.I did like you suggested (my next step was going to be canceling the fire function if it had already fired anyway but this was a far more efficient solution.)
The ten or so extra echoes dried up right when I did it, and I was posting a bug that I couldn't get locked down but when checking the post for typos I found a stupid idiot mistake I made instead - now it works. I've edited the post to reflect that I'm happy -- hooray.
I have a feeling I may have another question later, but thanks!
Associate Tom Eastman (Eastbeast314)
Hope that made sense and I understood the problem ;)