Hi,I'm currently trying to make a health bar for my HUD , in an RPG game, unfortunately, I can't go If(hp == 90) icon_state = "90hp" , because at a high level, 90 would be VERY low.
So, does anyone know how to do percentage?
ID:155391
![]() Jul 17 2011, 8:12 am
|
|
Oasiscircle wrote:
You wouldn't need to put the ,1 at the end of the round(). Actually, round(n) is equivalent to a floor() function, whereas round(n,1) will round to the nearest whole number. For simple displays like this, it probably doesn't matter, but it's important to keep in mind when doing heavier calculations. round(0.7) = 0 round(0.7,1) = 1 |
If you wanted the percentage to round to the nearest 10, you'd put round(X, 10) where X is the percentage calculation (current/max * 100).
|
Lige wrote:
BeignetLover wrote: > icon_state="[round(health/maxhealth*100,1)]%" It's giving me crap about constant expression, which I don't even know what that is, and it recognizes "HP/maxHP" as a full variable ;( Anyone know why? |
It's because you're attempting to set the variable to an expression at compile time. Instead of this:
obj You need this: obj |
Round() defaults to 1. ;)