Game Development Community

Pausing a for statement

by Tim Heldna · in Torque Game Engine · 07/28/2006 (8:47 am) · 6 replies

Is there a way in TS to pause a 'for' statement on each loop, without using a schedule?

Perhaps a 'wait' command or similar?

So if my 'for' statement ran for a total of 5 cycles, it would pause for 5 seconds (or however long I needed it to) after each increment.


Example:
function testLoop()
{
   for (%i = 1; %i <= 5; %i++)
   {
      echo("loop "@%i);
      wait(5000);
   }
}

This would echo "loop 1" to the console, wait for five seconds then echo "loop 2" and so on.

#1
07/28/2006 (9:08 am)
You'll have to use schedule. There's no such control in TorqueScript.
#2
07/28/2006 (9:09 am)
K, thanks.
#3
07/28/2006 (9:25 am)
You could expose platform::sleep() to script,
but of course, absolutely nothing would happen during the sleep.
no engine processing, no rendering, no network processing, etc,
so it's probably not what you want.
#4
07/28/2006 (9:40 am)
No, platform::sleep() isn't what I want. Nor is $timescale.

At the moment I'm looping between two functions with a schedule which is working fine, it's just a little messy for my liking.

Thanks for the suggestion though.
#5
07/28/2006 (11:03 am)
Why two functions?

I'd think you could do something like:

function slowFor(%pause, %i, %callback) {
  echo ("loop " @ %i);

  %i++;

  if (%i <= 5) {
    schedule(%pause, 0, slowFor, %pause, %i, %callback);
  }
}
#6
07/28/2006 (11:28 am)
Thanks Cliff, I tried that segment of code with no joy.

I'm doing a target range if anyone was wondering. I have it all working quite flawlessly. I'm now going through the process of condensing my code wherever I can. Thus the enquiry about a pause-able 'for' statement.

I have to show you a picture of the target. It's a classic! The guy is wearing happy pants and the hair, well take a look for yourself.

i5.photobucket.com/albums/y189/fjs/targetGame.png