# Health Bar Problem

5 replies to this topic

### #1 Fireelight

Fireelight

GMC Member

• GMC Member
• 109 posts

Posted 29 January 2012 - 03:38 PM

Hello, i have a problem with the function "draw_healthbar".
Well, i start with 150HP, but the healthbar don't start to decrease until it reaches 100.
I want to tell it that it should count with the "maxhp" not 100.
`draw_healthbar(view_xview[0] + 150,view_yview[0] + 25,view_xview[0] + 250,view_yview[0] + 45,obj_player.hp,c_black,c_red,c_green,1,1,1);`
My variables are:
hp = 150;
maxhp = 150;

Is this a common problem? Or am i just fumbling?

Edited by Fireelight, 29 January 2012 - 03:40 PM.

• 0

### #2 Misu

Misu

Awesometasticness!

• GMC Member
• 435 posts
• Version:GM:Studio

Posted 29 January 2012 - 03:54 PM

The problem is that the healthbar in Game Maker is a total max of 100 always and there is no way on how to adjust that except something lower. However, instead of calculating with exact amount you focus on (150), you should use percentage. Here is how:

The max hp is 150 ----> 150/100
```maxhp=(150/100);
hp=100```

Now we calculate (here is an example):
if hit by monster, player loses 10 health meter (-10)
You going to calculate by percentage.
if hit:
`obj_player.hp-=10/obj_player.maxhp`

Edited by MisuMen49, 29 January 2012 - 03:57 PM.

• 1

### #3 Fireelight

Fireelight

GMC Member

• GMC Member
• 109 posts

Posted 29 January 2012 - 03:59 PM

So instead of the amount in health bar(obj_player.hp), i will replace with obj_player.percentage?
• 0

### #4 Misu

Misu

Awesometasticness!

• GMC Member
• 435 posts
• Version:GM:Studio

Posted 29 January 2012 - 04:00 PM

oopsy! I edited that! Check again!
• 0

### #5 Fireelight

Fireelight

GMC Member

• GMC Member
• 109 posts

Posted 29 January 2012 - 04:05 PM

Yeah, now it works.
The healthbar decreases, but the string I've made looks very unprofessional, because it counts with the decimals. Like: Current Health: 51.67/150

Edit; Wait, can I just make new variables?

Double Edit; Yeah, i just made new variables "drawhp" and "drawmaxhp". I made drawhp decrease if i got hit, exactly as "hp" and drew them as the string instead.

Edited by Fireelight, 29 January 2012 - 04:10 PM.

• 0

### #6 Misu

Misu

Awesometasticness!

• GMC Member
• 435 posts
• Version:GM:Studio

Posted 29 January 2012 - 04:12 PM

In other words, Problem solved!
• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users