Individual, and always active, functions
by D B · in Torque Game Engine · 05/19/2006 (4:15 pm) · 2 replies
I was wondering if there is a way to have it so each PlayerData has its own individual function that is always running automatically.
To be more specific, I want to have the characters blink using IFLs, and be able to set blinking to on or off, as well as have a random blinking interval. I'm not asking for help about how to apply those functions; I'm just wondering if anyone could tell me if there's a way to have the functions work for individual characters automatically.
Thank you.
To be more specific, I want to have the characters blink using IFLs, and be able to set blinking to on or off, as well as have a random blinking interval. I'm not asking for help about how to apply those functions; I'm just wondering if anyone could tell me if there's a way to have the functions work for individual characters automatically.
Thank you.
About the author
#2
Also, thanks for all of the details you've provided, as well. The examples were very nice.
05/24/2006 (2:54 pm)
Thanks, Manoel! Very clever! :DAlso, thanks for all of the details you've provided, as well. The examples were very nice.
Associate Manoel Neto
Default Studio Name
There are two ways to use schedule. First as a console function:
Type that in the console, and you'll get a "hello world" after 3 seconds.
The first paramter is the time, the 2nd is the object. If you leave this 0, the function will be called as a console function. If you pass the name or the ID of some object, the function will be called as a method in that object. So, if you wanted to plant a time bomb in a player, you could do:
That'll call delete on the object named player3 after 3 seconds.
There is also an alternate way to schedule a call on a certain object:
You can also store the schedule in a variable, which allows you to stop it later:
And you can cancel the schedule this way:
Now, to make a function repeat itself over and over, just make it re-schedule itself and pass the same parameters on the schedule. By using getRandom() you can make it repeat in irregular intervals of time:
function Player::blink(%this) { %time = getRandom(1000, 5000); cancel(%this.blinkSchedule); %this.blinkSchedule = %this.schedule(%time, "blink"); //Code to do the blink animation goes here... }Note that I used cancel() before issuing a new schedule. This is a safekeeping measure, since if the blink() method is called from somewhere else other than the schedule, it'll create a new schedule before the previous one has fired, creating another "schedule thread", essentially making the funciton get called twice as much.