Game Development Community

Schedule event management

by Steven Meek · in Torque Game Builder · 12/15/2007 (8:42 am) · 3 replies

Hi, I'm working on a TD game which is fairly basic but just to get me into using TGB.

The gui is rather simple, besides the create towers buttons there is "Send Next Wave", "Restart", and "Quit" buttons.

The way I've coded the send next wave is it schedules an enemy for creation a t2dpath in intervals so each enemy is spaced out.... Here's the code;

for(%i = 0; %i < $max_num_objects; %i++)
{
schedule((700 * %i), 0, "addObject");
}

This gives all objects nice spacing..... the addobject() function put's each object into a simset of existing enemies for other purposed.

Now my problem is the Restart functionality. Each object is added to the simset (towers or enemies). The reset code simple does a delete on every object in those simsets, BUT the schedule function continue to churn out enemies if you hit reset in the middle of it scheduling each object for creation.

Is there a way to globally cancel all scheduled events as I use the schedules in other aspects of the game such as tower cooldowns and slow effects, so this would help me cancel other minor errors....

Anyone have any thoughts or experience with this? I'm thinking of maybe just creating some form of schedule wrapper, kind of like a simset of event id's so to say, but I was hoping there was a better/builtin way to handle this.

#1
12/15/2007 (11:08 am)
Unfortunately I don't think theres a simple way to globally stop all scheduled events. You would have to write a "schedule manager" to track them all. I remember someone posting code for this someplace in these forums, but I don't have the link.
#2
12/18/2007 (10:30 am)
If you tie the schedule to an object and delete the object, the schedules will also be deleted. It might also be a good idea so that "addObject" isn't a free-floating function but it belongs to an object (a little OO snobbery).

You could also put all of the schedules in an array and then delete all of the array elements on reset.
#3
12/18/2007 (8:14 pm)
Instead of scheduling the creation of enemies at the same location but different times to get their spacing. You could create them all at the same time, but at different locations on the spline. Just extend the spline back further off-screen to create the required space. The end result is the same, but now all your enemies are created at once, so you can safely delete them all upon reset.