Chronos |
From WoWDev
Chronos is a function library to make tracking timed tasks and distributed tasks easier.
Download the most recent release version from the curse site or the newest alpha contained in the Cosmos Alpha download. (You will also need Sea)
Example:
Chronos.schedule(10, foo, "a");
Will call foo("a") in 10 seconds.
Note: Do not include () after your function name, which coders tend do to often like Chronos.schedule(10, foo(), "a"); this causes your function to be called immediately and Chronos will try to "call" the return value of your function after the specified interval (which is not neccesarily bad if your function returns a function...)
Chronos.startTimer("SomeID");
foo()
delta = Chronos.endTimer("SomeID");
Will return the amount of time needed to run foo.
Chronos Documentation
Chronos Functions
- afterInit - runs a function after the game starts.
- schedule - schedules a function to be called after a delay
- scheduleByName - schedules a function to be called after a delay by name
- scheduleRepeating - schedules a function to be called repetedly every X seconds
- unscheduleByName - unschedules a function created by scheduleByName or scheduleRepeating
- isScheduledByName - determines if a function is scheduled already by scheduleByName or scheduleRepeating
- startTimer - starts a timer
- getTimer - returns the amount of time since the timer was started
- endTimer - ends a timer and returns the amount of time since the timer was started
- performTask - performs a complex task over multiple frames (use this to stop frame lag)
Template:Suggest in Discussion
Chronos Examples
Chronos.scheduleByName("TEST", 120, bar, "a");
Chronos.scheduleByName("TEST", 12, bar, "a");
Will call bar("a") after 12 seconds (overwriting the first timer).
Chronos.performTask(
{
begin = function() Sea.io.print("Hello!"); setglobal("a", 0); end;
step = function() Sea.io.print(getglobal("a")); setglobal("a", getglobal("a")+1); end;
end = function() Sea.io.print("Bye!"); end;
isDone = function() return ( getglobal("a") > 50 ) end;
}
);
Will print
Hello! 1 2 ... 50 Bye!
But it will do it over the course of 50 frames. Properly used, this can prevent "choppiness" and make a cpu intensive mod much much better.

