Raised This Month: $32 Target: $400
 8% 

broken floats?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nanochip
Senior Member
Join Date: Jan 2014
Old 02-11-2017 , 05:40   broken floats?
Reply With Quote #1

I am clueless as to what is happening right now or how to fix this..

my playerSpeed and top_speed variables are both floats.
playerSpeed is getting set OnGameFrame, which only gets set after a rocket deflect has occurred. I put a debug message to make sure it was only getting set once, and not repeatedly:
PHP Code:
    int client GetEntPropEnt(rocketProp_Send"m_hOwnerEntity");
    
playerSpeed[client] = DB_GetRocketSpeed();
    
PrintToServer("SetSpeed"); 


PHP Code:
    PrintToServer("%d %d"playerSpeed[client], top_speed);
    
PrintToServer("%d %d"playerSpeed[client] + 0top_speed); // notice how putting a + 0 breaks the float and resets it to 0 for some reason?
    
char derp[32];
    
IntToString(playerSpeed[client], derpsizeof(derp)); // this is a tag mismatch but wanted to see if it would reset back to 0...
    
PrintToServer(derp);
    
    if (
playerSpeed[client] > top_speed)
    {
        
PrintToServer("if statement worked");
    }
    
    
PrintToServer("hi"); 
my IF statement is not returning as true, even though the PrintToServer debug messages says it should return true.... so something really weird is going on here...

here's what the debug looks like:


so wtf?

EDIT: also rounding the floats would reset them back to 0. Furthermore, I've updated my compiler to the latest build and it still happens..
__________________

Last edited by Nanochip; 02-11-2017 at 05:47.
Nanochip is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-11-2017 , 05:53   Re: broken floats?
Reply With Quote #2

DB_GetRocketSpeed, did you make that function a float return?

Also to add to floats, you have to do + 0.0, or float(0).

These do show up as errors, I don't know why it didn't tell you anything post compiling...

Also floats are displayed as "%f"?

You said "my playerSpeed and top_speed variables are both floats."
Why are you using IntToString without changing the float to an Int?
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 02-11-2017 at 05:57.
OSWO is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 02-11-2017 , 08:15   Re: broken floats?
Reply With Quote #3

stop ignoring tag mismatch warnings
Miu is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 02-17-2017 , 13:18   Re: broken floats?
Reply With Quote #4

Quote:
Originally Posted by OSWO View Post
Also to add to floats, you have to do + 0.0, or float(0).
You don't have to do that, there is some autoboxing magic in the float support.
https://github.com/alliedmodders/sou...float.inc#L291

@OP Using floats as ints has all kind of undefined behavior.
__________________
Peace-Maker is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 02-17-2017 , 13:37   Re: broken floats?
Reply With Quote #5

You should use RoundFloat if you want to use it as an integer, if you want percision use %.1f to display only one decimal point.
Mitchell is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-17-2017 , 14:58   Re: broken floats?
Reply With Quote #6

Quote:
Originally Posted by Nanochip View Post
-snip-
Learn the format specifiers
headline is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-17-2017 , 15:26   Re: broken floats?
Reply With Quote #7

Quote:
Originally Posted by Peace-Maker View Post
You don't have to do that, there is some autoboxing magic in the float support.
https://github.com/alliedmodders/sou...float.inc#L291

@OP Using floats as ints has all kind of undefined behavior.
I've always received formating warnings if I do 'float' + 1 for example
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 02-17-2017 at 15:27.
OSWO is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 02-17-2017 , 15:46   Re: broken floats?
Reply With Quote #8

Quote:
Originally Posted by OSWO View Post
I've always received formating warnings if I do 'float' + 1 for example
Can you give an example where you have problems?
__________________
Peace-Maker is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-17-2017 , 16:10   Re: broken floats?
Reply With Quote #9

PHP Code:
float F_New 2
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-17-2017 , 16:42   Re: broken floats?
Reply With Quote #10

Hey buddy, mind scrolling up before you post a comment? Thanks.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO 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 22:25.


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