Raised This Month: $ Target: $400
 0% 

Modulo a float?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lolz123
Member
Join Date: Aug 2010
Old 01-29-2017 , 12:05   Modulo a float?
Reply With Quote #1

Im trying to do this:

PHP Code:
float fTimeLeft = (g_fStartGameTime 3.0) - GetGameTime();

if(
fTimeLeft 1.0 == 0)
{
    
// Play a sound
}

PrintToChatAll("%.1f seconds left"fTimeLeft); 
So every one second, a sound will be played.

But I'm getting this error:
Code:
error 004	function "operator%(Float:,Float:)" is not implemented
Why?
And if I can't use modulo with floats, is there a way around to do what I'm trying to do?
Something like fmod() function in C?

Thank you
Lolz123 is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 01-29-2017 , 12:24   Re: Modulo a float?
Reply With Quote #2

PHP Code:
stock float FloatMod(float numfloat denom)
{
    return 
num denom RoundToFloor(num denom);
}

stock float operator%(float oper1float oper2)
{
    return 
FloatMod(oper1oper2);

But, you want use 1.0 as denom that equal get decimal part of value. For this you can do:
PHP Code:
if(FloatFraction(fTimeLeft) == 0.0

    
// Play a sound

But all of this bad way. Just use 1.0 repeat timer.

Last edited by Kailo; 01-29-2017 at 12:46.
Kailo is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode