Code:
...
timeRemaining = timeRemaining - 0.01;
...
timeRemaining becomes 0 but it just keeps going without ever posting the NSLog message. timeRemaining is a float.
The recommendation for <= is in the "rules of the road" for comparing floating-point types. When comparing two floating-point values, you can use an
epsilon comparison (e.g., to tell if A is greater than B, you could use
and to tell if A "equals" B you could use
Code:
if ((epsilon <= (A-B)) && ((A-B) <= epsilon)) {
...
where
epsilon is your degree of precision. (For the A==B case, you can store A-B in a temporary but you still have to do the comparison twice.)
But I have a different question: is there a good reason that your counter is a floating-point and not an integer representation of that floating-point value. For example, reading the code you provided, I could use an int to perform the same thing (changed code highlighted in bold):
Code:
- (void) updateTimeRemaining: (NSTimer *) timer
{
if (blueButtonState == 2) // The timer should only be running if the game is still running.
{
[B]timeRemainingINT[/B] = [B]timeRemainingINT--[/B];
[B]float floatTime = 0.01*timeRemainingINT[/B];
timeRemainingLabel.text = [NSString stringWithFormat: @"Time Remaining: %3.2f Seconds", [B]floatTime][/B];
timeRemainingBar.progress = [B]floatTime[/B] / [roundTime.text floatValue];
if ([B]timeRemainingINT == 0[/B])
{
NSLog(@"Sees that the time limit is up.");
if (numberOfTeams.selectedSegmentIndex == 0)
{
NSLog(@"Sees that it's time to restart.");
}
}
}
}
I used a temporary for the float version of the timer because of too many years of paying attention to these kinds of things. Had it not been hundredth's of seconds as the unit of time, the multiplication factor would be that value (thousandth's or seventy-thirds or whatever).
RonC
(NOTE: I write Obj-C code like a C/C++ programmer because I'm a novice Obj-C programmer, but have been using C/C++ since 1984 when I was a newbie at Bell Labs. Yes, that means I'm an old fart.)