ID:155391   Jul 17 2011, 7:12 am 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?
 <-> Jul 17 2011, 8:25 am You wouldn't need to put the ,1 at the end of the round(). Round() defaults to 1. ;)
 <-> Jul 17 2011, 8:42 am so, would I just make icon states called 90 70 and 50 and so on?
 <-> Jul 17 2011, 9:21 am
 <-> Jul 17 2011, 9:25 am In response to Oasiscircle Oasiscircle wrote: You wouldn't need to put the ,1 at the end of the round(). Round() defaults to 1. ;) 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
 <-> Jul 17 2011, 9:31 am In response to DarkCampainger Oh, thanks for clarifying that! I never knew that.
 <-> Jul 17 2011, 9:35 am In response to BeignetLover 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).
 <-> Jul 17 2011, 8:42 pm Lige wrote: BeignetLover wrote: 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? ```> 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?
 <-> Jul 18 2011, 8:22 am In response to BeignetLover It's because you're attempting to set the variable to an expression at compile time. Instead of this: ```obj health_bar icon_state="[round(health/maxhealth*100,1)]%" var health maxhealthmob proc/take_damage(n) hp -= n health_bar.health -= n ``` You need this: ```obj health_bar proc/set_health(health,maxhealth) icon_state="[round(health/maxhealth*100,1)]%"mob proc/take_damage(n) hp -= n health_bar.set_health(hp, max_hp) ```