Timer Question

Blitz3D Forums/Blitz3D Programming/Timer Question

What code would i use to count in seconds how long my
program has been running for ?

thankyou

At the beginning of your program, set a StartTime variable. Just before your program ends set a StopTime variable.

Subtract the two and divide by 1,000 to get seconds.

StartTime = millisecs()
StopTime = millisecs()

DurationSeconds = StopTime - StartTime / 1000

It should be:

DurationSeconds = ( StopTime - StartTime ) / 1000

You don't need the StopTime, just replace with millisecs() again.

This shows how long the program is running, and you can change the offset so you can make it update every second, or minute, or whenever ;)

Global Time% = MilliSecs()

;Offset - The delay that you want the program to show how long it's been running
;This offset is set to 5 seconds

Global Offset% = (1000*5) ;5,000 milliseconds

Global UpTime% = Offset

Global Hours%,Minutes%,Seconds#

While Not KeyDown(1)
	Seconds = ((MilliSecs()-Time)/1000.0)
		
	If Seconds > 60
		Time = MilliSecs()
		Minutes = Minutes + 1
	EndIf
	
	If Minutes > 60
		Minutes = 0
		Hours = Hours + 1
	EndIf

	DisplayUpTime()
Wend

Function DisplayUpTime()
	TempCheck% = (Floor(Seconds)*1000)+(Minutes*1000*60)+(Hours*1000*60*60)
	
	If TempCheck => UpTime
		Print "Up-Time: " + Seconds + " Seconds : " + Minutes + " Minutes : " + Hours + " Hours"
		
		UpTime = UpTime + Offset
	EndIf
End Function