i'm thinking to make a tick timer, but i'm kinda lost as how to do it.
what i would like is:
a little clock/timer that counts down to zero. and on zero tells me a tick has occurred.
i'm planning to add triggers to sync the timer.
i was looking through the forum to see what's the best way to do this and permTimers were mentioned.
are those the times i can create under the timer icon?
how do i use them in a repeating manner?
and what if i wanna change the time interval dynamically?
and once i get that to work: how would i go about making it visual?
does anyone maybe have any working tick timer i could have a look at for ideas?
how to make a tick timer?
Re: how to make a tick timer?
There isn't much info on permTimers in the manual, but I've made re-occuring timers by encasing normal tempTimers in a function that calls itself when the timer completes.
For example my playing toggle:
If the function is passed a parameter of -1, it will fire again by calling the function again after a few (default of 5) minutes, over and over again with the parameter of -1. As long as the function is passed a parameter of -1, it will keep firing after 5 minutes. If any other number is given as the parameter (say, 10), the timer will kill the loop after the given time value (10 minutes) by calling the function again with a value of 0. A blank parameter also kills the loop.
Note: The function takes advantage of lua's inheritance model for functions (the self variable), which is described in the Programming in Lua book.
For example my playing toggle:
If the function is passed a parameter of -1, it will fire again by calling the function again after a few (default of 5) minutes, over and over again with the parameter of -1. As long as the function is passed a parameter of -1, it will keep firing after 5 minutes. If any other number is given as the parameter (say, 10), the timer will kill the loop after the given time value (10 minutes) by calling the function again with a value of 0. A blank parameter also kills the loop.
Note 1: The function takes advantage of the fact that a tempTimer() returns a unique timer index, and I assign that value to self.timer. When the timer fires, I clear the value from self.timer (as the timer has fired and no longer exists), then call the toggle function. If the function is called *before* the temp timer fires, then killTimer(self.timer) kills the still running timer, and I set self.timer to the new (if any) timer index.
Note: The function takes advantage of lua's inheritance model for functions (the self variable), which is described in the Programming in Lua book.
Re: how to make a tick timer?
The simplest way is to use GUI timer object (trigger editor -> timers -> new). GUI timer objects keep running while they are enabled. To enable/disable them via scripts: enableTimer(name) / disableTimer(name)
When the timer fires the timer script is being run. The interval of GUI timers cannot be changed via script. permTimer() is just a function to create GUI timers, but if you want to change the time interval this isn't what you want to use either.
To make timers with changing time intervals, you have to use tempTimers which are one shot timers. Note that you cannot change the time interval on a running timer because of cross platform OS limitations. If you need to change the interval of a running timer you have to stop the temp timer and destroy it (killTimer(id)) and then create a new tempTimer with the remaining time offset. Also take a look at Mudlet's stop watch functions that allow you to create you own complex timer frameworks if necessary.
When the timer fires the timer script is being run. The interval of GUI timers cannot be changed via script. permTimer() is just a function to create GUI timers, but if you want to change the time interval this isn't what you want to use either.
To make timers with changing time intervals, you have to use tempTimers which are one shot timers. Note that you cannot change the time interval on a running timer because of cross platform OS limitations. If you need to change the interval of a running timer you have to stop the temp timer and destroy it (killTimer(id)) and then create a new tempTimer with the remaining time offset. Also take a look at Mudlet's stop watch functions that allow you to create you own complex timer frameworks if necessary.