Archived

This topic is now archived and is closed to further replies.

Kheteris

Timer

Recommended Posts

Kheteris    122
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?

Share this post


Link to post
Share on other sites
Marty666    145
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
}

Share this post


Link to post
Share on other sites
Crispy    556
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.





Share this post


Link to post
Share on other sites