# How do I set a health bar width to variable based on % only?

Get help using Construct 2

### » Thu Sep 11, 2014 7:55 am

One of my projects has multiple variables I'd like to display as bars that shrink/grow based on the variable changes.

The issue I keep running in to is when I set the bar width = to the variable number I end up with different sized bars. The different variables are ranged from 100 to 13000 and the larger number produces a bar that goes off the screen.

I wanted to know if anyone has a simple way to shrink the bar width based on % instead of a number value, What i mean is; instead of showing 80/100 I would rather like to show 80%/100% so the bar that happens to be 30 pixels long will shrink percentage wise rather than grow to 100 pixels and then start to shrink.

Please let me know if you need clarification, It's a bit late and I know I start to get goofy after midnight haha.
B
15
S
5
G
2
Posts: 150
Reputation: 1,965

### » Thu Sep 11, 2014 8:15 am

you need two variabled: current health + Max health

width = (Current Health / Max Health) * Max Size of Bar

For example, if you have 30 HP left out of 50 and the bar has a max width of 150 pixels, the bar will be 90 pixels wide.

hope this helps you

EDIT: Sorry, was a mistake in my previous formula.
B
44
S
10
G
8
Posts: 437
Reputation: 6,483

### » Sat Sep 13, 2014 5:22 am

Ubivis wrote:you need two variabled: current health + Max health

width = (Current Health / Max Health) * Max Size of Bar

For example, if you have 30 HP left out of 50 and the bar has a max width of 150 pixels, the bar will be 90 pixels wide.

hope this helps you

EDIT: Sorry, was a mistake in my previous formula.

I tried this method and it doesn't seem to work. I end up with the current health variable dividing itself by the max width or "max health" veritable and only a sliver of the bar appears.
B
15
S
5
G
2
Posts: 150
Reputation: 1,965