Author Topic: Up Time Counter  (Read 4937 times)

Offline Synthetic

  • Mr. Drawsprite
  • **
  • Posts: 61
    • View Profile
    • ClanBam
Up Time Counter
« on: 2006-Jul-17 »
// --------------------------------- //
// Project: Up Time Counter
// Start: Sunday, July 16, 2006
// IDE Version: 3.179
// Here's another useful bit of code I came up with if you need a time counter.
// It counts seconds, minutes and hours.

//Grab starting timer position
//This gets the current timer position to start counting from.
//It has to be put where you want timing to start and should only be run once IE
//before the main loop or as the first part of the code in your program.
starttimesec = GETTIMERALL()
starttimemin = GETTIMERALL()
starttimehour = GETTIMERALL()

//Get temporary timer position minus the starting timer position.
//This gives us only the amount that has changed since the starting timer position
//was grabbed.
tempsec = GETTIMERALL() - starttimesec
tempmin = GETTIMERALL() - starttimemin
temphour = GETTIMERALL() - starttimehour

//Since GETTIMERALL() returns 1000ths of a second we divide by 1000 to get 1 second
//Not part of the actual code but to get minutes we need 60 total 1000ths of a second to = 1 min
//so we get 60000 by multiplying 60 x 1000.
//Similar with hours but since we now need 60 total minutes, that is 60 times the 60 x 1000ths
//(1min) which gives us 3600000 to divide by. If I lost you, don't worry, my description isn't that great.
//Also, GETTIMERALL() gives us a real number so we must use INTEGER() to give us a whole
//number by cutting off everything past the decimal point.
seconds = INTEGER(tempsec / 1000)
minutes = INTEGER(tempmin / 60000)
hours = INTEGER(temphour / 3600000)

//This sets the starting time positions up to grab the current timer position for another count once
//minutes or seconds have reached 60.
//Since hours count up continually, we don't need to modify the starting position for them unless you
//wanted to add a counter for days, years, etc..
IF minutes > 59 THEN starttimemin = GETTIMERALL()
IF seconds > 59 THEN starttimesec = GETTIMERALL()

//This should be easy to figure out but we are just pasting the timer results to
//the screen and then telling it to update so it can be seen.
PRINT "Up Time: " + hours + "h" + minutes + "m" + seconds + "s",200,100
"Impossible is a word people use to make themselves feel better when they quit."

My AMXMODX plugins for Day of Defeat 1.3 can be found here.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2751
    • View Profile
Up Time Counter
« Reply #1 on: 2006-Jul-17 »
Very nice routine (and well documented), thank you,



“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)