Game Development Community

Cancelling All Scheduled Events

by James Randall · in Torque Game Builder · 02/20/2006 (3:05 am) · 9 replies

Is there a simple way to cancel all scheduled events?

I have a number of scheduled events running and the only reason I have for tracking the IDs of those events is to cancel all outstanding events when the player ends the game.

#1
02/20/2006 (3:45 am)
Every time you create a scheduled event go like this:
$schedule[$numSchedules] = schedule(...);
$numSchedules++;

Then when you want to cancel them all go like this :

for (%c = 0; %c < $numSchedules; %c++)
{
// I don't know how to check if the scedule still exists though it doesnt really matter
cancel($schedule[%c]);
}
#2
02/20/2006 (3:56 am)
Thats what I'm doing at the moment. I was just looking for a better way as otherwise I don't care about them. I thought it would be nice if I could just say to the Torque engine - kill all the scheduled events.
#3
02/20/2006 (4:11 am)
Just put it in a function called cancelAllSchedules() ... then you have your own function to tell the engine to do that :)
#4
02/20/2006 (4:16 am)
I think this thread is revealing just how lazy I am.... :)
#5
02/20/2006 (11:43 am)
There is no mass schedule killer in the engine by default. It is trivial to add one however. Of course, doing so requires a recompilation of the engine, which probably makes Chris' solution the 'lazier' way to go. :) His is also generally better for reasons I'll mention below.

You'll need to add the following to console/simManager.cc around line 110:

void cancelAllPendingEvents()
{
   SimEvent **walk = &gEventQueue;
   SimEvent *current;
   
   while((current = *walk) != NULL)
   {
      *walk = current->nextEvent;
      delete current;
   }
}

Add the following to console/simBase.h at line 1270:

void cancelAllPendingEvents();

And finally, add the following to console/simBase.cc around line 435:

ConsoleFunction(cancelAllSchedules,void,1,1,"cancelAllSchedules()")
{
   argc;
   Sim::cancelAllPendingEvents();
}

This probably isn't in the code already because it is kind of dangerous. A lot of stuff uses schedules and this blows them *all* away without discrimination, so be careful. :) Keeping track of your schedules as Chris' script solution does is almost always the better thing to do.
#6
02/20/2006 (11:47 am)
Oh, and you can check to see if a scheduleID is still pending by calling 'isEventPending(%scheduleID)' though don't bother to test if the event is pending before cancelling it, because both just walk the event queue the exact same way, one returning a value the other removing it if it exists.
#7
02/20/2006 (12:04 pm)
I'm convinced.

I'll stick with the script!

Thanks for all the replies.
#8
06/26/2009 (2:11 pm)
You can have all scheduled events associated with an object and then delete the object to cancel them.

objectName.schedule(9999, "functionName");
objectName.safeDelete();

Since objects are deleted when a level unloads, you can use this method to be sure that the schedules will be canceled.
#9
06/29/2009 (3:25 pm)
i think that another way to doit is, basically the same explained in the 1st post, but using simsets, since those are some kind of arrays that autoupgrade when a value of it is deleted, you just need to know how big the simset is, and off you go...