Scripted timer
by Bill Henderson · in Torque Game Engine · 03/11/2002 (3:51 pm) · 8 replies
Hello,
I was wondering how you would go about scripting a timer seperate from the mission clock.
For like a time bomb.
I was wondering how you would go about scripting a timer seperate from the mission clock.
For like a time bomb.
About the author
#2
03/11/2002 (5:11 pm)
Thanks, it was exactly what I needed.
#3
I know in javascript there was a function to cancel any queued "orders". One such example would be having the bomb be defused. Currently, it'd blow up since the command is stored to go off after a set amount of time.
I know there are other ways of doing this (like checking some state at the time the function is triggered with the timer) but one of the interesting features of javascript was the ability to cancel timer stuff.
03/11/2002 (5:13 pm)
One question, I know I haven't looked into it (nor do I really need it) but can schedules be cleared?I know in javascript there was a function to cancel any queued "orders". One such example would be having the bomb be defused. Currently, it'd blow up since the command is stored to go off after a set amount of time.
I know there are other ways of doing this (like checking some state at the time the function is triggered with the timer) but one of the interesting features of javascript was the ability to cancel timer stuff.
#4
03/11/2002 (5:17 pm)
yes, they can be cleared... but i cant remember how! :\
#5
03/11/2002 (7:13 pm)
I don't know about in Torque, but in Tribes 2 you can use the follow scheduling stuff (note that I've just modified the previous example and that you should create your own bombObject for use with it):// Starts the time bomb
function startTimeBomb(%bomb, %time)
{
%bomb.time = %time;
%bomb.schedule = schedule(1000, 0, "decBombTime", %bomb);
}
// Decreases the time left on the bomb countdown
function decBombTime(%bomb)
{
%bomb.time--;
if(%bomb.time <= 0)
{
// Do bomb blowup code here
return;
}
else
{
// Otherwise, keep scheduling the countdown...
%bomb.schedule = schedule(1000, 0, "decBombTime", %bomb);
}
}
// To start the timer...
startTimeBomb(bombObject, 10);
// To cancel the timer at any point...
Cancel(bombObject.schedule);
#6
There is two ways to do a schedule. Object based and Normal.
Normal
Object Based - note. If the object gets removed so does the schedule.
Object based schedules are much safer.
eg. If you create a schedule for a client on join game, that schedule will then be deleted when the client leaves. Much cleaner :)
03/11/2002 (9:09 pm)
I am not sure if your example will work Daniel, it may do. I think that it would confuse the issue.There is two ways to do a schedule. Object based and Normal.
Normal
%myschedule = schedule(500, 0, "runme", %bla);
function runme(%bla)
{
}
//to cancel
cancel(%myschedule);Object Based - note. If the object gets removed so does the schedule.
%obj.myschedule = %obj.schedule(500, "runme", %bla);
function ObjectType::runme(%obj, %bla)
{
}
//to cancel
cancel(%obj.myschedule);Object based schedules are much safer.
eg. If you create a schedule for a client on join game, that schedule will then be deleted when the client leaves. Much cleaner :)
#7
The second argument in a schedule (I believe) works the same way. If you set the second arg to an object, then when that object gets deleted, the schedule gets canceled.
03/11/2002 (11:57 pm)
It is cleaner, in a sense.The second argument in a schedule (I believe) works the same way. If you set the second arg to an object, then when that object gets deleted, the schedule gets canceled.
#8
The second variable in the schedule command determines if it is activated or not yes but it does not have to be an object. It can be any true/false statement.
A value of false will make the schedule work and a value of true will make it not work.
(At least from my experience...I personally stick with the object oriented schedules)
03/12/2002 (3:35 am)
Yes and NoThe second variable in the schedule command determines if it is activated or not yes but it does not have to be an object. It can be any true/false statement.
A value of false will make the schedule work and a value of true will make it not work.
(At least from my experience...I personally stick with the object oriented schedules)
Torque Owner Chris "Dark" Evans
function startTimeBomb(%bomb, %time) { %bomb.time = %time; schedule(1000, %bomb, decBombTime, %bomb); } function decBombTime(%bomb) { %bomb.time--; if(%bomb.time <= 0) { // Do bomb blowup code here return; } else schedule(1000, %bomb, decBombTime, %bomb); }