How do I create a stopwatch
BlitzMax Forums/BlitzMax Beginners Area/How do I create a stopwatch
| ||
I need a simple stopwatch on screen. (Just the numbers) It needs to start at 00:00 and count up. 00:00:01, 00:00:02, 00:00:03... ..00:00:59, 00:01:00, 00:01:01, 00:01:02 etc. accurately counting seconds, minutes, hours on and on until I tell it to stop. I have experimented with CurrentTime(), MilliSecs(), and CreatTimer() but have been unable to figure out how to make any of those work correctly. Did a search in the forum for stopwatch, clock, timer and none of these resulted in anything close to what is needed. This is probably real beginners stuff - but hey, I'm a beginner. Thank you very much for any help given. Emmett |
| ||
Here is the simple version:Local starttime = MilliSecs() While True seconds = (MilliSecs()-starttime)/1000 Print seconds / 3600 + ":" + (seconds / 60) Mod 60 + ":" + (seconds) Mod 60 EndWhile |
| ||
Including the milliseconds:Local starttime = MilliSecs() While True milseconds=MilliSecs()-starttime seconds = milseconds/1000 Print seconds / 3600 + ":" + (seconds / 60) Mod 60 + ":" + (seconds) Mod 60+":"+milseconds Mod 1000 EndWhile |
| ||
Thanks Again - Works Great. Here is a working snippet of how it's plugged into a program - less any other code of course. Graphics 1024, 768 Global starttime=MilliSecs() Repeat seconds = (MilliSecs()-starttime)/1000 DrawText seconds / 3600 + ":" + (seconds / 60) Mod 60 + ":" + (seconds) Mod 60, 800,175 Flip Cls Until KeyHit (KEY_ESCAPE) End |