Using percentage for healthbar animation

I have a health bar, its has a near invisible scale on frame 1, on frame 100 its the biggest I want it to be. I want to be able to use the percentage of my max health left to determine the size of the bar.

is my script completely wrong?

cont = bge.logic.getCurrentController()
own = cont.owner

import bpy

if own['health'] > own['healthMax']:
   own ['health] = own['healthMax']

if own['health'] < 0:
   own['health'] = 0

own['divide'] = (100 / own['healthMax'])
own['percent'] = (own['divide'] * own['health'])

Heres pics of logic bricks and script
[ATTACH=CONFIG]140381[/ATTACH]

Attachments

DynamicHealthHUD.blend (1.22 MB)

always use the console to debug your scripts. click the ‘abc’ button in the text editor, it shows up simple syntax errors like this: (own['health]).


cont = bge.logic.getCurrentController() 
own = cont.owner 

if own['health'] > own['healthMax']:    
    own ['health'] = own['healthMax']  

if own['health'] < 0:    
    own['health'] = 0  

own['divide'] = 100 / own['healthMax'] 
own['percent'] = own['divide'] * own['health']

cont.activate(cont.actuators['FCurve'])


attach the fcurve actuator to your script and try again-
bpy is not needed and should not be used in game engine.

I tried what you said and fixed the script, however its still not working and it doesnt keep health from going over healthMax… Does it matter if when I play game the debug property shown on screen says healthbargreen.health and healthbargreen.percent etc etc.

Im using 2.56 btw.

[ATTACH=CONFIG]140413[/ATTACH]

I got it to work with this

import GameLogic as l
cont = l.getCurrentController() 
own = cont.owner 

if own['health'] > own['healthMax']:    
    own ['health'] = own['healthMax']  

if own['health'] < 0:    
    own['health'] = 0  

own['divide'] = 100/own['healthMax'] 
own['percent'] = own['divide']*own['health']

if own['percent'] > 100:
    own['percent'] = 100

thank you for the help