Here's a little something I found when searching through the Amazingcookie archives*!
It's the code used in the Taskbar Stopwatch to determine how the time should be calculated. I tried to comment it as well as I could, but if there are questions, please comment!
// Calculate/Berekenen
global.milsecond = current_time - global.starttime - global.waittime - global.shrinker
if global.milsecond >= 1000 {global.milsecond = global.milsecond - 1000 ;global.shrinker = global.shrinker + 1000; global.second = global.second + 1 }
if global.second == 60 { global.second = 0; global.minute = global.minute +1 }
if global.minute == 60 { global.minute = 0; global.hour = global.hour +1 }
// Draw/Tekenen
if global.milsecond <= 100
{if global.milsecond <= 10
set_application_title(string(global.hour)+':'+string(global.minute)+':'+string(global.second)+',00'+string(global.milsecond)+' - ►')
else
set_application_title(string(global.hour)+':'+string(global.minute)+':'+string(global.second)+',0'+string(global.milsecond)+' - ►')
}
else
set_application_title(string(global.hour)+':'+string(global.minute)+':'+string(global.second)+','+string(global.milsecond)+' - ►')
// End of code
Legend:
current_time: A variable in Game Maker. This is the time elapsed in milliseconds since the computer was turned on.
global.starttime: When the application is started or Play is pressed after the stopwatch has stopped, this variable is set to be the same as current_time. So, in fact, the elapsed time is the same as current_time - global.starttime.
global.waittime: This is the total time that the stopwatch was PAUSED. This is also subtracted from the total time, without being added in the shown time.
global.shrinker: Shrinker is mainly there to make sure the milliseconds counter in the taskbar shows a number delow 1000. If it's higher, then add a second to the counter.
Then it gets obvious. If there are 60 seconds, add a minute and set seconds to 0, if there are 60 minutes, add a hour and put minutes to 0.
Then we update the time in the toolbar. First, it checks how many zero's it needs to draw, and then it updates it with the correct data.
*In fact it was a Writer document I had prepared to present sometime ago. I absolutely love this Writer tool. See why