startStopWatch/stopStopWatch Usage Questions

Post Reply
kog
Posts: 2
Joined: Mon Oct 16, 2017 1:49 am

startStopWatch/stopStopWatch Usage Questions

Post by kog » Mon Oct 16, 2017 2:06 am

Having done some digging around, I discovered I'm not the only one running into the 'problem' of stopStopWatch/resetStopWatch not actually doing anything with regards to the current time on the timer - it just keeps ticking up and up and up. So I'm going to be lazy now and ask in case someone knows, before I go digging:
- Will it bog my Mudlet instance down to just keep discarding/creating new ones? If I need to measure time elapsed between event a and b, then another time between event a and b, I could just make a new stopwatch every time, but is that going to fill memory up with lots of ticking intricate things, or is it just saving the system time since it was created and showing me the time elapsed every time I call the stop?
- Is there a way to delete the stopwatch?
- Is there another function that I'm missing that I could use, or are there plans to fix the resetStopWatch function? I'd very much like a way to count down and be able to see how long is left until an event - for example, a frog hops every 30 seconds. How do I periodically check if n seconds have elapsed since the last time the frog hopped, or simply see how many seconds since the last frog hop?

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

Re: startStopWatch/stopStopWatch Usage Questions

Post by Vadi » Mon Oct 16, 2017 4:04 am

The implementation is very efficient - as in, there's nothing actually ticking. It just remembers the time and gives you a delta every time you check.
1) well I'd re-use them, but you'll be find creating new ones.
2) nop
3) create a timer for 30s that resets the stopwatch, start the stopwatch - then 30 - stopwatch time will be how much is left!

kog
Posts: 2
Joined: Mon Oct 16, 2017 1:49 am

Re: startStopWatch/stopStopWatch Usage Questions

Post by kog » Mon Oct 16, 2017 4:28 am

Awesome, I'll just re-declare the variable then! That's the simple route, and it should work for what I need. Much appreciated.

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

Re: startStopWatch/stopStopWatch Usage Questions

Post by Vadi » Mon Oct 16, 2017 4:55 am

Use this pattern to automatically re-use an existing stopwatch:
Code: [show] | [select all] lua
fightStopWatch = fightStopWatch or createStopWatch()

User avatar
SlySven
Posts: 778
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK

Re: startStopWatch/stopStopWatch Usage Questions

Post by SlySven » Sun Oct 29, 2017 3:27 am

"The implementation is very efficient - as in, there's nothing actually ticking." Are you sure of that Vadi? Each stopwatch uses a distinct QTime instance.

For the record, a stopwatch has a maximum period of a 23h 59m 59s and it can get things wrong if the system's clock is adjusted or - and it is something worth mentioning as I have experienced it within the last few hours - your locale's Daylight Saving Time state gets changed...

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

Re: startStopWatch/stopStopWatch Usage Questions

Post by Vadi » Sun Oct 29, 2017 6:33 am

Yep I'm sure, because the line I gave only creates 1 stopwatch however many times it is called.

User avatar
SlySven
Posts: 778
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK

Re: startStopWatch/stopStopWatch Usage Questions

Post by SlySven » Tue Oct 31, 2017 5:29 am

That wasn't quite what I meant - it was more that once a stopwatch is created with createStopWatch() there is no means to subsequently destroy it in that session.

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

Re: startStopWatch/stopStopWatch Usage Questions

Post by Vadi » Tue Oct 31, 2017 5:33 am

Yes, I was talking about a different kind of efficiency:

> The implementation is very efficient - as in, there's nothing actually ticking. It just remembers the time and gives you a delta every time you check.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests