Functions not reseting
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()
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 ]
//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 ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement