Advertisement Jump to content


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

The Pale Hunter

Functions not reseting

This topic is 6178 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve got a function called CLOCK::WaitClock() that determines if a certain amount of time has gone by since it was called, and returns TRUE if it has. My problem is this...when I do something like : if (CLOCK::WaitClock(2000)) { . . . } it works okay, but if later on I make the same if statement, it already thinks WaitClock is returning TRUE instead of FALSE...i.e. it isn''t waiting. Any ideas? Here is what the actual function looks like: bool CLOCK::WaitClock(DWORD count) { static DWORD startTime = 0; DWORD currentTime = 0; static int check = 0; //We only want to initialize startTime once if (check == 0) { startTime = GetTickCount(); check = 1; } //Update the current time currentTime = GetTickCount(); DWORD longEnough = count; //If enough time has elapsed, return true if ((currentTime - startTime) > longEnough) { return 1; } else { return 0; } }//end WaitClock()

Share this post

Link to post
Share on other sites
Your own comment explains it all:

//We only want to initialize startTime once

If startTime is only ever initialised once, then as soon as 2000 ticks have passed, it will always return false, won''t it? Every time you call it, startTime will be the same.

If you''re trying to make it count how long since the last time it was called, you need to add startTime = currentTime before the return 1 (which should really be return true).

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!