Raised This Month: $12 Target: $400
 3% 

RoundTo... returning 0


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-19-2015 , 00:12   RoundTo... returning 0
Reply With Quote #1

Code:

PHP Code:
    float AmmoClip;

// .... some other operations here

    
int AmmoInt RoundToCeil(Ammo);
    
int ClipInt RoundToCeil(Clip);
    
    
PrintToChatAll("Ammo: %d %d, Clip: %d %d"AmmoAmmoIntClipClipInt); 
The printout in-game:

Code:
Ammo: 24 0, Clip: 16 0
The 24 and 16 are correct but they are floating point numbers in the code. I want them to be integers. Why is RoundToCeil returning 0?
Potato Uno is offline
VoiDeD
AlliedModders Donor
Join Date: Mar 2009
Location: Illinois, USA
Old 09-19-2015 , 01:02   Re: RoundTo... returning 0
Reply With Quote #2

Because `Ammo` and `Clip` don't contain float data, they contain ints. Your PrintToChatAll is printing them as %d, which would output considerably different looking values if they were actual floats.
__________________
VoiDeD is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-19-2015 , 09:50   Re: RoundTo... returning 0
Reply With Quote #3

So even though I tagged them as a float, they are internally integers?
Potato Uno is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 09-19-2015 , 14:52   Re: RoundTo... returning 0
Reply With Quote #4

yes, sourcepawn doesn't do implicit conversions for assignments or actual paramters, you would ahve a tag mismatch warning somewhere unless you did something funny
Miu is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-19-2015 , 16:24   Re: RoundTo... returning 0
Reply With Quote #5

Quote:
Originally Posted by Potato Uno View Post
So even though I tagged them as a float, they are internally integers?
If you try printf in other languages, you'll run into this same problem. You can pass a float to a integer specifier, but it will be treated as if its value is an integer value.

Remember: A float is actually a pair of values that represent a x*2y algorithm.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Reply


Thread Tools
Display Modes

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:17.


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