Here's my first contribution to "Code Snippets."
I needed to display the elapsed time in my game and didn't find this time on the site"
Here is the code that calls the function:
startTime = timer()
do
cls
elapsedTime$ = elapsedTime(startTime)
text 10, 10, elapsedTime$
loop
Here is the function:
function elapsedTime(timeStart)
currentTime=TIMER()
currentTime = currentTime - timeStart
currentTime = currentTime / 1000
remainingSeconds = currentTime mod 360
if remainingSeconds > 59 rem at least a minutes' worth of seconds
minutes = remainingSeconds / 60
seconds = remainingSeconds mod 60
else
seconds = remainingSeconds
endif
if currentTime > 359 rem at least an hours' worth of seconds
hours = currentTime / 360
endif
hours$ = str$(hours)
minutes$ = str$(minutes)
seconds$ = str$(secondS)
if len(hours$) < 2 then hours$ = "0" + hours$
if len(minutes$) < 2 then minutes$ = "0" + minutes$
if len(seconds$) < 2 then seconds$ = "0" + seconds$
dispTime$ = hours$ + ":" + minutes$ + ":" + seconds$
endfunction dispTime$
Hope someone fins it useful.