Timer

Started by
1 comment, last by Kheteris 20 years, 3 months ago
How does one use time to implement different actions? Like I want the x variable to be 1, but after 25 seconds I want it to be 25. I know there''s a time.h header file, but I only know how to generate random ints with it... So, how do I get a timer to count?
Advertisement
You don''t get a timer to count.

I use timeGetTime() to look up the current system time and save it to a variable then look up how mutch time has passed by substracting that variable from the current timeGetTime(). You can make a simple if statement:

if (timeGetTime() - OldTime > 25000)
{
//this will happen 25000 milisecs after you got OldTime
}
_____ /____ /|| | || MtY | ||_____|/Marty
quote:Original post by Kheteris
How does one use time to implement different actions?

Like I want the x variable to be 1, but after 25 seconds I want it to be 25.

I know there''s a time.h header file, but I only know how to generate random ints with it...

So, how do I get a timer to count?


Hmm - sounds like you''re using the timer.h I posted a long time ago on these boards (if you''re not, you can always take it from the MySQL tutorial code, linked to on Nehe''s front page). If that is the case, just call TTimer:ush() when you want to reset the timer to zero (such as at the beginning of program execution) and test for TTimer:op() whenever you like to get the number of milliseconds that have passed since last calling Timer:ush().

Or you could use Marty''s code.




"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

This topic is closed to new replies.

Advertisement