Countdown timer

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Countdown timer

Post by tsuujin »

timer can be an object that's instantiated and then manipulated instead of a single command

local t = timer.new()
t.setTimeout(60)
t.onInterval(10,[[some code every ten seconds]])
t.onInterval(15,[[some code every 15 seconds.]])
t.onTimeout([

Code: Select all

])
t.start()

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Countdown timer

Post by Vadi »

That makes sense to go with actually. Would be easy to specify custom remaining time warnings as well... ie t.onTimeRemaining

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Countdown timer

Post by tsuujin »

whole thing would be a lot easier to do on the Lua side if Lua had some form of threading with WAIT, but I haven't seen anything like that. Really you'll just have to store times and commands, then create self refreshing tempTimers for intervals, and another for the timeout (which would kill all existing timers). Information would be saved, and then bulk executed on start().

It gets more complex if we want a pause() function. Would have to store the start time in the object, and the current time at the pause. This would be used to determine how long the timer has already been going, and continue() would subtract the executed time from the total time to get remaining times on everything. Easy with the main timer, but a bit more complex with the intervals.
You'd also have to decide if you wanted to refresh the interval times on a pause, or for one round use the remaining times and refresh to normal interval on the execute. The user could want to specify which of these options to use, too, for different situations.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Countdown timer

Post by Heiko »

A cool down timer can easily be done with a timer object that uses Mudlet's stop watches (-> stop watch functions).

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Countdown timer

Post by tsuujin »

cool, Stop Watches solve a few problems for me. Though, I kind of wish they were in object-oriented format (stopwatch.new() stopwatch.start()) but that's me being nit picky.

Post Reply