Delay problem
by Nathan Cox · in Torque Game Engine · 09/10/2007 (5:54 am) · 6 replies
I need to know the script to add a delay, like 30 sec or something.
About the author
#2
Would that work? I dont know how many milliseconds to a second.
09/10/2007 (10:26 am)
So say i did this:function setTime(%value)
{
%timeleft = %value;
}
function displayTime()
{
if(%timeLeft =< 0)
{
chatHud.addline('%timeleft seconds is the time left');
%timeleft -= 30;
schedule(30000, 0, "displayTime");
}
}Would that work? I dont know how many milliseconds to a second.
#3
Try this:
Type displayTime(30); into the console to start a 30 second count down. There are 1000 milliseconds in 1 second.
09/10/2007 (6:54 pm)
That's a good effort, it won't work but you were close.Try this:
function displayTime(%time)
{
if(%time)
{
if(%time != 1)
chatHud.addline(%time @ " seconds is the time left");
else
chatHud.addline(%time @ " second is the time left");
%time--;
schedule(1000, 0, "displayTime", %time);
}
else
chatHud.addline("Time is up");
}Type displayTime(30); into the console to start a 30 second count down. There are 1000 milliseconds in 1 second.
#4
09/11/2007 (12:59 am)
Thanx! how could i make and event happen wen the time is up??
#5
09/11/2007 (1:13 am)
The last else statement is where you want to put any events that occur once the time is up. As you have probably noticed I already threw in a text message of "Time is up" when the counter hits zero. You could either add some more code in there or just call another function.
#6
09/11/2007 (3:24 am)
Thanx that was brilliant help here i have a nearly finished script://pass out script by Ashandmisty
function startPassout()
{
displayTime(30);
startSleep();
}
function startSleep()
{
if(%time != 0)
{
commandtoserver('sleep');
schedule(1000, 0, "startsleep");
}
}
function displayTime(%time)
//your script will go here
movemap.bind(keyboard, "q", 'startpassout');
Torque Owner Tim Heldna
You can also cancel a schedule. Do a dump or check the docs for more information.
There's no explicit pause or delay command - you can achieve the same affect using the schedule function and bouncing between functions if necessary.