"sleeping" the code
by Glen "ThaBonadingus" Reece · in Torque 3D Professional · 10/21/2010 (6:36 pm) · 5 replies
Hello. I have one little itty bitty problem that I am trying to resolve. I am looking for some kind of sleep(); or wait(); command. For those who have no idea what I am talking about here's a scenario. Lets say the function wait(number); makes the code wait 1 second before moving on to the next line in a function. Like this:
function test()
{
while (%a < 3)
{
wait(1); //wait one second before proceeding
%a++;
echo(%a); // count off the seconds
}
}
if wait(1) told the code to wait 1 second before proceeding, then every second (until 3 has passed) a would output the second and then loop so it would "echo" %a in the console every second.
is there any function like that in TorqueScript, other than schedule()?
If my explanation is just bad, I'm comparing it to the Sleep(int); function in c++.
function test()
{
while (%a < 3)
{
wait(1); //wait one second before proceeding
%a++;
echo(%a); // count off the seconds
}
}
if wait(1) told the code to wait 1 second before proceeding, then every second (until 3 has passed) a would output the second and then loop so it would "echo" %a in the console every second.
is there any function like that in TorqueScript, other than schedule()?
If my explanation is just bad, I'm comparing it to the Sleep(int); function in c++.
About the author
Christian, Star Wars fan, Expert Americanese Speaker, The Legendary Bonadingus boss monster, Frighteningly Sexy, Lover of Anime (especially Gundam), MangaPage and ItBGames Partner, and IndieOtaku Blogger.
#2
Oh well, that just means I will have to learn a new way of doing my loops and such. Thank you Daniel.
10/21/2010 (11:05 pm)
ok, so there is no way to use the c++ sleep function without writing it into another function for TorqueScript in a header either I suppose.Oh well, that just means I will have to learn a new way of doing my loops and such. Thank you Daniel.
#3
What all kinds of "time" functions are there?
10/22/2010 (10:31 pm)
ok. Got one more question in result to this question being asked. How can I find out how much time has passed. For instance in mili seconds or seconds?What all kinds of "time" functions are there?
#4
10/24/2010 (4:10 am)
I think there is a couple of global variables for time. $gameTime or something like that. If you look at the code of a ClockGUI in game that should get you started.
#5
10/24/2010 (2:02 pm)
Thank you Jesse. I did see some of those but was not 100% sure of their use. But thank you, I can look into it. ;)
Torque 3D Owner Daniel Eden
Below is an equivalent to your function above coded in Torque. It counts from one to three with one second pauses in between outputting the results to the console. Note that this version of the function doesn't ensure there's only a single version of itself running (something you could do easily enough by storing the schedule id and then calling cancel at the beginning of the function itself).
// Test function. function test(%value) { // If there's a value, increment it or if not, initialize it. %value = (%value !$= "") ? (%value + 1) : 1; // Echo to the console. echo(%value); // If the value is smaller than 3... if (%value < 3) { // Schedule the next call in one second's time, passing it the value. schedule(1000, 0, "test", %value); } }