stopwatch?
Blitz3D Forums/Blitz3D Programming/stopwatch?
| ||
Hello, I can make a timer time begins in high numbers and down. 10:11:50 .. 10:11:49 .. 10:11:48 .. |
| ||
Hi you can use CreateTimer()/Millisecs() to check if a 'second' is passed and decrease your 'clock'. You need to track Hours, Minutes & Seconds and write all the logic behind (>60 seconds means 1 Minute, 60 Minutes means 1 Hour etc) edit: (BlitzMax source, but the logic is the same) |
| ||
here is a pure blitzbasic solution:Graphics 320,200 Global H%=4 Global M%=30 Global S%=0 Global Time=MilliSecs() Global Clock$ Repeat Cls Text 100,100, Clock$ CheckTime Flip 1 Until KeyHit(1) Function CheckTime() If MilliSecs()>Time Time=Time+1000 S=S-1 If S<0 M=M-1 S=59 End If If M<0 H=H-1 M=59 End If clock = RSet("00" + H,2) +":" + RSet("00" + M,2) +":" + RSet("00" + S,2) EndIf End Function |
| ||
Thanks You. :) |
| ||
Hi , I have been able to implement the chronometer , however I have no idea how to put it on pause and then continue. Any suggestions .![]() |
| ||
Hi just use a global like timer_pause to change in the main game loop. If timer_pause=1 CheckTime() will skip to count, otherwise it acts normally. |
| ||
@degac No work, Apparently enters paused but resumed when the time has passed , for example if it stops at 45, and when reaunudo was 30 . Graphics 320,200, 32, 2 Global H%=4 Global M%=30 Global S%=0 Global Time=MilliSecs() Global Clock$ Global timer_pause = 1 Repeat If KeyHit(200) timer_pause% = 1 - timer_pause Cls Text 100,100, Clock$ CheckTime Flip 1 Until KeyHit(1) Function CheckTime() If timer_pause=1 If MilliSecs()>Time Time=Time+1000 S=S-1 If S<0 M=M-1 S=59 End If If M<0 H=H-1 M=59 End If End If Clock = RSet("00" + H,2) +":" + RSet("00" + M,2) +":" + RSet("00" + S,2) EndIf End Function |
| ||
Ok, no problem.Function CheckTime() If MilliSecs()>Time Time=Time+1000 If timer_pause=1 S=S-1 If S<0 M=M-1 S=59 End If If M<0 H=H-1 M=59 End If End If Clock = RSet("00" + H,2) +":" + RSet("00" + M,2) +":" + RSet("00" + S,2) EndIf End Function How do I get milliseconds look ? 01:55:99 Minutes, Seconds, millisec. |
| ||
Hi ops... I did an error when I wrote the code, I've no more Blitz3d installed, so I tested something similar (not implying Millisecs()) in Bmax. Well, technically, you check the time every 1000 millisecs... so if you check Millisecs()>Time2+10 you can count them. |
| ||
@degac Thanks You.![]() I have always something new to learn . Global Mi%=1 Global Se%=59 Global Ml%=99 Global timeC Global Clock$ Function CheckTime() If MilliSecs()>timeC timeC=timeC+1000 If menu%=False Ml=Ml-1 If Ml<0 Then Se=Se-1 Ml = 99 End If If Se<0 Mi=Mi-1 Se=59 End End If End If Clock$ = RSet("00" + Mi,2) + ":" + RSet("00" +Se ,2) +":" + RSet("00" + Ml,2) EndIf End Function |
| ||
Oops, problem here: 2 minutes Stopstopwatch. if Clock$ ="" End. 01:00: 00 change a to 00:00:00 exit program, One minute lost. :( Edit : No problem, Error en my code. :) |
| ||
Global Mi%=0 Global Se%=10 Global Ml%=99 Global timeC Global Clock$ ; - Update Volantes. ; ------------------- Function CheckTime() If MilliSecs()>timeC timeC=timeC+100 If menu%=False Ml=Ml-1 If Ml<0 Then Se=Se-1 Ml = 99 End If If Se<0 Mi=Mi-1 Se=59 End If End If Clock$ = RSet("00" + Mi,2) + ":" + RSet("00" +Se ,2) +":" + RSet("00" + Ml,2) EndIf End Function This seems to work properly, but it is not, the second are very delayed , are not real , any suggestions? |
| ||
there is a start/stop timer in the codearchives: Race Timer Functions it is counting up, but can be paused. |
| ||
@ Dan Thanks You. Is there any way to put a high boot on time. For example Start two minutes down the counter. ? |
| ||
Graphics3D 800, 600, 32, 2 camara% = CreateCamera() Global ml% = 99 Global mi% = 10 b% = LoadFont("blitz",30) SetFont b s% = MilliSecs() While Not KeyHit(1) If MilliSecs() > s% s% = s% + 10 ml% = ml% - 1 End If If ml% < 0 Then mi = mi - 1 ml% = 99 End If If mi% < 0 mi% = 0 ml% = 0 End If RenderWorld Text 0, 0, ml% Text 0, 50, mi% Flip Wend Ok, no problem, I 'm understanding the millisecs command ( ) |
| ||
if you need hundredth you have to optimize the code. First problem is, that with "FLIP 1" the code only repeats 60 times a second, but you would need 100 times. 60 times a second means that Millisecs() increases 16msec every repeat, but your TIME only increases 10msec. So TIME will have a (continously growing) delay. So you have to do this: Graphics 320,200,0,2 Global H%=4 Global M%=30 Global S%=0 Global Small%=0 Global Time=MilliSecs() Global Clock$ Repeat Cls Text 100,100, Clock$ CheckTime Flip 0 Until KeyHit(1) Function CheckTime() If Time > MilliSecs() Return While MilliSecs()>Time Time=Time+10 Small=Small-1 If Small<0 S=S-1 Small=99 EndIf If S<0 M=M-1 S=59 End If If M<0 H=H-1 M=59 End If Wend clock = RSet("00" + M,2) +":" + RSet("00" + S,2) +":" + RSet("00" + Small,2) End Function The small interval of 10msec will stress your computer. To prevent this you could only use an interval of 100msec and fake the last digit: Graphics 320,200,0,2 Global H%=4 Global M%=30 Global S%=0 Global Small%=0 Global Time=MilliSecs() Global Clock$ Global timer_pause = 0 Repeat Cls Text 100,100, Clock$ CheckTime If KeyHit(2) timer_pause = 1-timer_pause EndIf Flip 1 Until KeyHit(1) Function CheckTime() Local count%=0 While MilliSecs()>Time Time=Time+100 If timer_pause=1 Return Small=Small-1 If Small<0 S=S-1 Small=9 EndIf If S<0 M=M-1 S=59 End If If M<0 H=H-1 M=59 End If clock = RSet("00" + M,2) +":" + RSet("00" + S,2) +":" + RSet("0" + Small,1) +Rand(0,9) Wend End Function |
| ||
@MideMaster Thanks You :) |
| ||
As evaluated when a zero comes ?if clok$ = "00:00:00:00" End No working here. |
| ||
no, the time is over when H=0 and M=0 and S=0 and SMALL<1. |
| ||
@MidiMaster. Thanks You. :) |