Need help getting a simple health bar working

Hi, I followed the tutorial in the link below to step #4. I only want the health bar.

I did everything as the tutorial said it.
However, the tutorial has basic python and was made in 2008, so I imagine the python part changed.

Basically, the health bar starts out at it’s smallest point and stays that way.
I tried using the left/right arrow keys to decrease/increase the size of the bar and it didn’t work.

I am not very experienced at all with Python, so I wouldn’t know what changes to the code need to be made to work.

If you can’t get to the page for some reason, here is the code:

import GameLogic
cont = GameLogic.getCurrentController()
own = cont.getOwner()
own.percent = * 100 / own.healthMax

YES, I named the file correctly and made the actuators just as the tutorial says.

Will someone update this code?
If you do and it works, I’ll post you a picture of a kitten.

I suppose I should actually have tried to figure out the code.
The code is irrelevant to the problem, in fact. It’s obviously just for the percentage.

In that case, I must have to do something else different in Blender 2.49.

Im pretty new to Python aswell, but I do know that you just have to have two bars that are animated with scale so they are full at the first frame and empty on the last, then just make the properties for the bars.

…I know that. I did the tutorial. The problem is that the python is old and I don’t know how to update it.
Did you read my post through?

Yes, let me look at maybe I can find the new python script.

I might be able to find it.

You won’t, the script is fine.
I have to find my error and it may take a while.
Thanks anyway

Here is how the script should look like in 2.49:

import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner
own['percent'] = own['health'] * 100 / own['healthMax']

Try that and see if it works

A “simple” health bar can be done without Python, and if you don’t know what you’re doing with python, maybe you should try plain logicbricks.

The general idea is to have a bar that has an animation that scales itself from zero health to full health. Then you can use the IPO actuator to control that bar’s size with a property (Play Property). You can have it copy the health attribute from your player with the property actuator.

I made a little demo (plus a minigame!) to demonstrate this. You really should only have to look at the health bar to see how this is all done.



healthbar.blend (43.4 KB)

Thanks for the reply, but I already figured out how to do it with logic bricks. It took a little trial and error to understand the various sensors, but the healthbar works fine now.

Andrew, thanks for the code clairification. Now I know some of the changes since Dec 2008 in Python.

I’m updating the wiki, everything is a bit WIP so far but I actually wrote a health bar example a couple of hours ago

(And for sensors )

It seemed to work for me.:confused: