Ints VERSUS Floats (solved)

Started by DrewCCU, Tue 06/07/2010 00:53:53

Previous topic - Next topic

DrewCCU

Hello everyone.  If you're American I hope you had a happy Independence Day.  If you're not American, I hope your July 4th went well. LoL.

Anyway ...

I have looked through the help files and read up on Floats and Ints and FloatToInt and IntToFloat and all of that stuff.  So i know what a float is versus an int.  But i still don't fully understand how you use these in AGS.  Up to this point I've learned to use ints and floats enough to get by in AGS without fully understanding how they operate within AGS.  But i've come to the point where i need to know how they work inside the program.

What i need is something like this:

float GP = Game.SpriteHeight[frame.Graphic] / 1.1888888888888888888888888888889

The only way i can get something similar to this to work is:

int GP = Game.SpriteHeight[frame.Graphic]/FloatToInt(1.1888888888888888888888888888889);

Which turns the non whole number into an int which ends up rounding it.  And it's affecting the calculation so i'm not getting the desired result because i'm getting a number thats been rounded.  Not an exact number which is what i need.  If this makes no sense then let me know and i'll try to clear it up. thanks.

EDIT:
Does the following code account for scaling or is it simply the default graphic size??

ViewFrame *frame = Game.GetViewFrame(cEgo.NormalView, 0, 0);

in other words, does getting this particular frame account for this frame being scaled in the room?  Or is it only the size that the graphic was imported (therefor, nothing else - not even scaling - would effect the outcome)

"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

Gilbert

If you need to do arithmetic operations with floating point numbers, convert ALL the numbers to floating point numbers first and change the result back to an integer AT THE END (if required).

Things like "int/FloatToInt(1.188888888889)" never works as this is merely translated to "int/1".

i.e. something like:
Code: ags

float GP = IntToFloat(Game.SpriteHeight[frame.Graphic])/1.1888888888888888888888888888889;

or
Code: ags

int GP = FloatToInt(IntToFloat(Game.SpriteHeight[frame.Graphic])/1.1888888888888888888888888888889);

depending on whether you want the result to be an integer or a floating point number.

About the ViewFrame problem, no, it won't get the scaling factor in this way. You need
to check cEgo.Scaling to see whether the character is scaled at a particular instant in the game.

SMF spam blocked by CleanTalk