as I can create a timer?
Blitz3D Forums/Blitz3D Programming/as I can create a timer?| 
 | ||
| I want to create a timer that starts at a high value and fall with the course of time, for example 60 seconds to zero seconds. Any examples? | 
| 
 | ||
| An example (seconds increasing count and seconds decreasing count) : Graphics3D(640,480,32,2) OldMs% = MilliSecs() NowMs% = MilliSecs() NowS% = 0 RemainingS% = 60 While( KeyDown(1)<>1 ) NowMs = MilliSecs() If( NowMs - OldMs => 1000 ) NowS = NowS + 1 RemainingS = RemainingS - 1 OldMs = NowMs EndIf If( RemainingS = 0 ) ;do something here EndIf SetBuffer(BackBuffer()) ClsColor(000,000,000) Cls() Color(255,255,255) Text(0,0,"NowS = "+NowS) Text(0,20,"RemainingS = "+RemainingS) Flip(1) Wend End() | 
| 
 | ||
| Graphics 400,300,32,2 SetBuffer BackBuffer() timer = 60 ; seconds timer_start = MilliSecs() Repeat Cls time_left = timer-(MilliSecs()-timer_start)/1000 Text 10,10,time_left Flip Until time_left <= 0 End | 
| 
 | ||
| You may want to put a leading zero in front of numbers less than 10 if you want to simulate a digital clock display. | 
| 
 | ||
| My code archives entry. Uncomment the code and run the example. | 
| 
 | ||
| Hello, thank you very much, I agree with Matty, I need a stopwatch to clock an explosive.   | 
| 
 | ||
|  I need to create a timer like the image. Any suggestions? | 
| 
 | ||
| That's easy Yue. hectic's Draw3D2 is your solution :-)  http://www.blitzbasic.com/Community/posts.php?topic=92270 But I see you already know that with your posts there. Still having problems? | 
| 
 | ||
| If you're looking for digital fonts, just try these http://www.dafont.com/ds-digital.font http://www.1001fonts.com/digital-7-font.html check the licensing though, mostly they are for personal use or just purchase for commercial. | 
| 
 | ||
| What I do is a timer like a bomb, timer code above presents me only seconds, but I would like a stopwatch: 01:30:99 Minutes. seconds Milliseconds. | 
| 
 | ||
| Well, with Millisecs() you will get a timestamp in 1/1000 seconds. Please define all variables as INTEGER StartTime=Millisecs()
....
Repeat
     CurrentTime=Millisecs()You can add values to this timestamp to get into the future (30*60*1000 for 30 minutes x 60 seconds). With The difference you will get the remaining time StartTime=Millisecs()+ 30*60*1000
....
Repeat
     CurrentTime=Millisecs()
     Remaining = StartTime - CurrentTimeNow we do the isolation of 1/1000, seconds and minutes. If you divide the value by 1000 you will get how many seconds remain. If you do a MOD operation you will get the trunc of the 1/1000: StartTime=Millisecs()+ 30*60*1000
....
Repeat
     CurrentTime=Millisecs()
     Remaining = StartTime - CurrentTime
     AllSeconds = Remaining / 1000
     Thousand = Remaining MOD 1000Now we calculate the minutes by doing the same with the seconds: StartTime=Millisecs()+ 30*60*1000
....
Repeat
     CurrentTime=Millisecs()
     Remaining = StartTime - CurrentTime
     AllSeconds = Remaining / 1000
     Thousand = Remaining MOD 1000
     Minute = AllSeconds / 60
     Second = AllSeconds MOD 60Now You have three variables MINUTES, SECONDS and THOUSANDS, which you can re-combine to a string. Have a look on the definitions of the INTEGERs: StartTime%=Millisecs()+ 30*60*1000
....
Repeat
     CurrentTime%=Millisecs()
     Remaining% = StartTime - CurrentTime
     AllSeconds% = Remaining / 1000
     Thousand% = Remaining MOD 1000
     Minute% = AllSeconds / 60
     Second% = AllSeconds MOD 60
    Time$=Minute + ":" + Second + ":" + Thousand
    Print TimeThe rest is cosmetic. If one of the values is 0, you only will get one figure, but for good looking you will need two like: "00:00:000". So replace the time$ line:     Time$=Right("00" + Minute,2) + ":" + Right("00" + Second,2) + ":" + Right("000" + Thousand,3)
    Print Time | 
| 
 | ||
|  @Midimaster  Thanks You. :) |