Thinking about creating a countdown timer for the LuaGlobal API. Has anyone played around with the idea? The problem here is making it convenient and simple to use.
From what I can see there are two things to do here - intervals, and what to do at specific intervals. Intervals should also be either custom times, or just time deltas to use (ie every 5s). What to do should be either strings to echo or functions to execute.
That's pretty vague, but it's what I got in my head atm. Will add more refinement / comments welcome.
Countdown timer
Re: Countdown timer
I thought about doing this myself. The problem I had was with precision. Lua's timers, for what I can see, aren't precise (they just go by seconds, rather than microseconds) which kind of ruined my purpose for creating such a thing. I'd want as many decimals as possible in the counter.
Re: Countdown timer
Lua doesn't have timers, and Mudlets timers do go by decimals.
Re: Countdown timer
lua has os.clock(), which can be used to tell you how long, in minutes and seconds, the program has been running. It's just plain seconds, though, with no microseconds.Vadi wrote:Lua doesn't have timers, and Mudlets timers do go by decimals.
As far as I know, you can't arbitrarily set a mudlet timer and just call to see how long it's been running, which is what you'd really need.
Re: Countdown timer
if we could get a timer with, say, four decimals to start counting upwards when mudlet is instantiated then an awsome timer class would be a few keystrokes away. Really I think it has to be done on the C++ side.
Re: Countdown timer
oh hey, cool. I still have this old function from my MUSH system. Here's how I calculated time differences there:
Re: Countdown timer
Mudlet works around Lua's os.date not reporting miliseconds as well: http://mudlet.org/asciidoc/manual.html#getTime
But this isn't the question at hand... an easy to use API for creating a countdown timer to fill all kinds of needs while being easy to use for newbies too is what's problematic.
But this isn't the question at hand... an easy to use API for creating a countdown timer to fill all kinds of needs while being easy to use for newbies too is what's problematic.
Re: Countdown timer
without any extra level of precision, how's it different than just creating a permTimer interface?
Re: Countdown timer
Oh, sorry. It'll have the additional feature of doing actions as the time is closer to expiring.
Re: Countdown timer
Some ideas...
-- countdown timer for 60s that every 10s will print a msg
countdownTimer {endin = 60, {interval = 10, echo = "$timeleft seconds left! $timepassed seconds passed"}}
-- or can use a custom function...
countdownTimer {endin = 60, {interval = 4, echo = function(timeleft, timepassed) ... end}}
... also need a way to stick things to do when the time expires / give customized intervals. Just rough ideas.
-- countdown timer for 60s that every 10s will print a msg
countdownTimer {endin = 60, {interval = 10, echo = "$timeleft seconds left! $timepassed seconds passed"}}
-- or can use a custom function...
countdownTimer {endin = 60, {interval = 4, echo = function(timeleft, timepassed) ... end}}
... also need a way to stick things to do when the time expires / give customized intervals. Just rough ideas.