Properties Problem!

Hi
I have an object with 3 properties ,
Max Health
Health
Health Percentage

I guess they are obvious what their use is but I have a problem with the 3rd one…
I make an actuator as followed:
assign to Health Percentage:
(Health/Max Health)*100
in order to get the percentage but the value Health Percentage always goes to -1
I tried making Max Health and Health floatings but I still get a result of -1

What I want: I want to calculate the percentage of health remaining to the “hero” of the game so I can fix the health bar, I would do it with python but I dont know how to control properties so if anyone suggests python plz help me how to control them :slight_smile:

Are you really using space within the properties name?

Try without spaces

i’ve done this for mine. hold on
Animate the healthbar to move through 100 frames, from 1 =nothing
101 = full.
if you’re using 2,5* you can start at 0 and go to 100, but you must remove the “+1” in the code
Also, you may need to remove the import GameLogic if not using 2.5

import GameLogic
controller = GameLogic.getCurrentController()
owner = controller.owner

#get division
#divides 100 by full health (100 / 100)
healthm= 100 / owner["fullhealth"]

#get percentages and add 1
#because 2.49 starts ipo at 1
#times health by health multiplier
healthpercent = (owner["health"] * healthm)+1
    
#set the position from the percent var
owner["finalhealthipo"] = healthpercent


ok

  • don’t use spaces in property names
  • convert 100 to float (100.0)
  • perform the multiplication first:

100.0*health/max

ok thx a lot I will try these suggestions as soon as possible ,
btw Monster I tried different things like no spaces when I was expirimenting with python to find a solution but I ended up with nothing so thx anyway I will stop using spaces from now on haha

Spaces are not wrong for property names, but I think the expression controller and the property actuators can’t deal with them.

Monster thx a lot, your way seems the best ;DDDD
agoose77 sorry I didnt try your way because Monster’s was simplier but I will save it somewhere for future help if I need :wink:

btw I havent posted many stuff on blenderartists is there anyway to make this thread “solved” or something similar?
or I just leave it like that?

mine was the same XD
just complete code

You can add [solved] to the title by editing your first post (in advanced mode).