Page 1 of 1

How do you format a stopwatch

Posted: Fri Dec 10, 2010 7:21 pm
by Silvine
Hopefully a simple one. I want to use a stopwatch to display how long I have been logged on. It runs off a trigger from the welcome message, and updates to a status window every tick. But how do I format the stopwatch to show hours, mins, seconds?
I did try another approach that stored my login time in a variable and the tick time in another variable, but could not get one to subtract from the other as they are strings.
An answer to either or both approaches would be helpful, Thanks.

Re: How do you format a stopwatch

Posted: Sat Dec 11, 2010 1:19 am
by Silvine
Got it sorted for what i want it to do. I'll post answer in case its of use to anyone else.
Use a stopwatch that starts when you log in, then on the tick get the stopwatch time and then convert it into your own clock.
Code: [show] | [select all] lua
currenttimestop = getStopWatchTime(logtimestop)

seconds = currenttimestop % 60 
minutes = ((currenttimestop - seconds) / 60) % 60
hours = (((currenttimestop - seconds) /60 - minutes) / 60) % 60

echo( "status", "You have been playing "..hours..":"..minutes..":"..seconds.."\n")