Need some help with float (SOLVED)

Started by JD, Thu 16/06/2005 23:27:21

Previous topic - Next topic

JD

Hi,

In my game I want to show the health of a monster as a percentage as a label on a gui.
I tried:

int pc = ( 100 / ( GetGlobalInt(13) / GetGlobalInt(12) ) );


But since I can't have any decimals with ints, I had to find another way to do it because if the
enemy had 50 health out of 60, it would still show as 100%. CJ told me to use a float so I
looked into that stuff but I can't figure out how it works. I tried

float pc = ( 100 / ( GetGlobalInt(13) / GetGlobalInt(12) ) );

But that results in a Error (line 265): Type mismatch: cannot convert 'int' to 'float'. Don't
you use floats just like you use int or string?

Thanks in advance,

Def

strazer

Try
  int pc = (GetGlobalInt(12) * 100) / GetGlobalInt(13);

JD

Argh why didnt I think of that :) Thanks a lot Strazer!

strazer

#3
Hehe, you're welcome. :)

Edit:

Btw, your float line would've had to look like this:

  float pc = 100.0 / ( IntToFloat(GetGlobalInt(13)) / IntToFloat(GetGlobalInt(12)) );

SMF spam blocked by CleanTalk