Date: Mon, 15 Feb 1999 21:39:35 -0500 Message-Id: <199902160239.VAA29017@envy.delorie.com> From: DJ Delorie To: djgpp AT delorie DOT com In-reply-to: <7aajof$jnv$1@nnrp1.dejanews.com> (message from beergod on Tue, 16 Feb 1999 02:05:07 GMT) Subject: Re: need to use the timer References: <8D53104ECD0CD211AF4000A0C9D60AE3535851 AT probe-2 DOT acclaim-euro DOT net> <7aajof$jnv$1 AT nnrp1 DOT dejanews DOT com> Reply-To: djgpp AT delorie DOT com > well i am writing a game, a tomagotchi-like game.... and i need to > test when it's time to burp... i was planing to do this by getting > the time when he eats... and store it in a varable... then i was go > to check the time at the begaining of the main loop... if > then a > certain value then it would run the burp routine... i hope that this > will help u in asisting me. thanks This is easy, then. At the time the trigger event happens (eating, in this case), do this: eat_time = time(0); Note that you could also do "time(&eat_time)" or "eat_time = clock()" (clock has greater precision than time, but seconds should be enough for you). Later, do this: if (time(0) - eat_time > 60) burp(); The "60" means it will happen 60 seconds later. Don't forget to note that you've done that event, something like this: if (time(0) - eat_time > 60 && burp_time - eat_time < 0) { burp_time = time(0); do_something(); } Which means "If we haven't eaten in 60 seconds, and the last time we burped was before we last ate, burp, and remember that we burped so we don't keep doing it over and over again." Note I've used time differences, rather than comparing absolute times, so that if your game is ever running when the time value exceeds 31 bits (it could happen), the times wouldn't compare right but the differences would (as long as the differences were less than, say, 20-30 years :)