The Daily Click ::. Forums ::. Klik Coding Help ::. Can counters not deal with floating point?
 

Post Reply  Post Oekaki 
 

Posted By Message

Scott Handelman



Registered
  19/05/2004
Points
  117
14th July, 2004 at 19:19:55 -

So I made this stupid little shooting game where bunnies appear randomly on the left and right. I use one global variable to hold onto the number of bunnies killed and another to hold onto the number of times I've clicked. On the next screen, I put the # of kills in a counter and the (# of kills/# of clicks)*100 in another counter to create an accuracy rating. The first counter works fine. The second counter, no matter what I do, always reads zero. Is a counter not able to round up or down, does it just not read floating point numbers? Is there some other, more reliable way to print a global value to the screen?

 
n/a

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
14th July, 2004 at 19:31:33 -

Are you using MMF?

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

RapidFlash

Savior of the Universe

Registered
  14/05/2002
Points
  2712
14th July, 2004 at 19:32:57 -

It should use floating numbers (for MMF, at least). Just in case, for the equation, add a decimal in there. So if our equation was 1 + 1, then we'd do:
1.0 + 1

 
http://www.klik-me.com

David Newton (DavidN)

Invisible

Registered
  27/10/2002
Points
  8322

Honored Admin Alumnus
14th July, 2004 at 20:35:03 -

Without decimals, the second counter will always read zero because of the way you're doing the calculation. It's first dividing the number of kills by the number of clicks, which will always be a number below 1 - this is rounded down to zero. This is then multiplied by 100, which is of course zero again.

To avoid the problem, use the formula (# of kills * 100) / # of clicks instead. That way you won't lose as many significant figures (i.e. all of them).

 
http://www.davidn.co.nr - Games, music, living in America

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
14th July, 2004 at 20:40:26 -

Set the minimum option on the counter down. Maybe that helps?

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

Tigerworks

Klik Legend

Registered
  15/01/2002
Points
  3882
14th July, 2004 at 20:44:23 -

In MMF, add 0.0 to tell MMF to use floats.
In TGF, multiply by 100 first, to get a rounded percentage.

E.g. MMF: 0.0 + (Amount / Total) * 100
TGF: (Amount * 100) / Total

MMF will give a more accurate float answer, but they are both essentially the same result.

 
- Tigerworks

Scott Handelman



Registered
  19/05/2004
Points
  117
14th July, 2004 at 22:04:41 -

Thank you Wong Chung and Tigerworks. I should have guessed that the program would round after doing every operation. I was using MMF so I'll try adding 0.0, but both were very helpful. Thanks.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click