Game Development Community

Cycling script

by Joe Martin · in Torque Game Engine · 12/02/2008 (10:52 pm) · 2 replies

What I want to experiment with is having a small bit of script to be called without user interaction. I need it to be running every tick or every so many ticks depending on how much it overloads processing speed. My questions are, "Where would I place script to run without being event driven?" and "Where would I initially call it to get it started?"

If you're unsure on what I'm trying to do, picture a for loop in C++ that is the main loop of the game. And in that for loop is various calls to functions that need to be cycled through the entire time the game is running and one of those functions is the one I'd be working on.

#1
12/03/2008 (12:08 am)
Schedule(); is what you are looking for:
schedule(%time, id/0, function, args...);

put the function definition and the call for the function anywhere in script that gets processed.

function cycleScript()
{
  foo...
  bar...
  schedule(1000, 0, cycleScript());
}

cycleScript();
#2
12/03/2008 (8:39 am)
Okay, I figured I'd have to use the schedule to make sure it wasn't running every millisecond, so that clears that up. So I embed a call to the function inside the function I want to cycle? Is that what recursion is? Anyway, I'm going to give this a try tonight after work. Thanks!