Floats are unprecise, do not compare floats like

if (Float1 == Float2)

Because this will most likely not be true, even if they have the same value. 
Go read about how floats work for more information.

Instead you can use this approach

 if ( GetRoundRemainingTime() < flStartSuddenDeathSound && 
flStartSuddenDeathSound  > 0)
{
    // Emit your sound here
    flStartSuddenDeathSound  = -1.0f; // So this code doesn't run twice.
}

----- Original Message ----- 
From: "Yorg Kuijs" <[email protected]>
To: <[email protected]>
Sent: Tuesday, December 16, 2008 3:36 PM
Subject: [hlcoders] Round remaining time


> Hey list,
>
> maybe a stupid question but don't know whats wrong..
> My mod uses round based play, so besides a Maptime it has roundtime as
> well, I copied the maptimeremaining function and so have a
> roundtimeremaining function, works FINE.
>
> But now I have a float(can be an int too) to start suddendeath, the
> value is always set to: 30.0
> but now I have a sound that needs to start several seconds earlier, so I
> made another float, which was 35.0 and now that doesn't work. After some
> mucking around I found out that 30.0 works, so there's no problem with
> the second float, but if the value of the float isn't 30 then it doesn't
> work!
> The if statement goes like this:
> if ( GetRoundRemainingTime() == flStartSuddenDeathSound )
>
> like I said, if flStartSuddenDeathSound = 30 then it works, if it's not
> then it doesn't work!(possible some other value's work too, but not
> gonna test all the numbers.... tested 35 and 40)
>
> the RoundRemaining returns time as float, and a float of simple 30 is 30
> seconds, for some reason if its not 30 then it doesn't work.
> What's wrong here?
>
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list archives, 
> please visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
> 


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to