Getting a percentage between two variables

Status
Not open for further replies.

KadoDragon

Veteran
Veteran
Joined
Sep 10, 2013
Messages
155
Reaction score
9
First Language
English
Primarily Uses
So I've got three variables. One is PlayerHP, another is PlayerMaxHP and the last one is HPPercentage. I want to get a percentage between PlayerHP and PlayerMaxHP and store it into HPPercentage.

- When initialized PlayerHP = 100 and PlayerMaxHP = 100.

- I take PlayerHP and store it into HPPercentage

- I then take HPPercentage and divide it by PlayerMaxHP

- then I muiltiply HPPercentage by 100 and I should get the result.

At first when both PlayerHP and PlayerMaxHP are the same being 100 it works perfectly fine. I get a percentage output of 100. But the second PlayerHP drops below the 100 then something goes wrong and I get a Percentage output of 0. If PlayerHP is above PlayerMaxHP I get an output of 100 when it should be higher than 100. What is going on here?
 

Zoltor

Veteran
Veteran
Joined
Jan 18, 2014
Messages
1,550
Reaction score
211
First Language
English
Primarily Uses
So I've got three variables. One is PlayerHP, another is PlayerMaxHP and the last one is HPPercentage. I want to get a percentage between PlayerHP and PlayerMaxHP and store it into HPPercentage.

- When initialized PlayerHP = 100 and PlayerMaxHP = 100.

- I take PlayerHP and store it into HPPercentage

- I then take HPPercentage and divide it by PlayerMaxHP

- then I muiltiply HPPercentage by 100 and I should get the result.

At first when both PlayerHP and PlayerMaxHP are the same being 100 it works perfectly fine. I get a percentage output of 100. But the second PlayerHP drops below the 100 then something goes wrong and I get a Percentage output of 0. If PlayerHP is above PlayerMaxHP I get an output of 100 when it should be higher than 100. What is going on here?
Seeing how I've been doing alot of calculations with variables lately, and succeeding at such, I would most likely beable to help you, but I really need to see the actual event(s) that you have handling this.
 

ShadowLurk

Tanoshii~
Veteran
Joined
Feb 14, 2014
Messages
226
Reaction score
53
Primarily Uses
It drops to 0/100 because you divide by maxhp first. As it is an integer division, the remainder is dropped. Try multiplying it by 100 first.
 
Last edited by a moderator:

KadoDragon

Veteran
Veteran
Joined
Sep 10, 2013
Messages
155
Reaction score
9
First Language
English
Primarily Uses
It drops to 0/100 because you divide by maxhp first. As it is an integer division, the remainder is dropped. Try multiplying it by 100 first.
Oh would look at that. This worked. Thanks!
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,669
First Language
German
Primarily Uses
RMMV
Yes, you need to multiply first - that's the whole trick for a lot of integer operations...


This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top