as I can create a timer?

Blitz3D Forums/Blitz3D Programming/as I can create a timer?

Yue(Posted 2015) [#1]
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?


RemiD(Posted 2015) [#2]
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()



Flanker(Posted 2015) [#3]
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



Matty(Posted 2015) [#4]
You may want to put a leading zero in front of numbers less than 10 if you want to simulate a digital clock display.


Dan(Posted 2015) [#5]
My code archives entry.
Uncomment the code and run the example.


Yue(Posted 2015) [#6]
Hello, thank you very much, I agree with Matty, I need a stopwatch to clock an explosive.




Yue(Posted 2015) [#7]


I need to create a timer like the image.

Any suggestions?


RustyKristi(Posted 2015) [#8]
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?


RustyKristi(Posted 2015) [#9]
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.


Yue(Posted 2015) [#10]
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.


Midimaster(Posted 2015) [#11]
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 - CurrentTime



Now 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 1000


Now 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 60


Now 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 Time


The 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



Yue(Posted 2015) [#12]
@Midimaster


Thanks You. :)