Using % and / in formulas

Status
Not open for further replies.

ajilejay

Veteran
Veteran
Joined
Jul 17, 2013
Messages
64
Reaction score
0
First Language
English
Primarily Uses
I am trying to create a formula to which involves my missing health, However whenever I use % it just acts like a subtraction example 420%320=100. Whenever I use / it drops anything <1. So I am finding it impossible to create anything based off my missing health. So I have gone to ridiculously confusing measures to get around this and it still doesn't work.

<ft: add_param atk (100-(((mhp-hp)*100)/mhp)*(0.1*atk))/100>

If im at 100% HP mhp - hp = 0 so 0/ anything * anything should still be 0 and it should return as 0 but it doesnt even do that. This is the most frustrating thing. I don't know what to do at this point. How do I stop it from throwing out results that <1!?
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
What script are you using? I take it that's something that happens in addition to, or in place of, the damage formula on the skill tab?


I think dropping anything less than 1 is normal - it shouldn't do fractions, if that's what you mean.


And in a formula, % does not mean percent. It means modulus. So 420%320 means "how many are left over when you divide 420 by 320 evenly?" - the answer is 100.


Can you explain what you're trying to do? How is the value meant to be worked out? Your formula above is ALWAYS going to end up with something less than 1.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
No, your formula is wrong. At full HP that evaluates to 1.

(100-(((mhp-hp)*100)/mhp)*(0.1*atk))/100

mhp - hp * 100, this is done first. It comes out to to 0.

(100-(0/mhp)*(0.1*atk))/100

0 / mhp = 0

(100-(0)*(0.1*atk))/100

0.1 * atk = *some number that isn't important*

(100-(0)*(~number~))/100

0 * number = 0

(100-0)/100

100 - 0 = 100

100 / 100 = 1

there's your issue.
 

ajilejay

Veteran
Veteran
Joined
Jul 17, 2013
Messages
64
Reaction score
0
First Language
English
Primarily Uses
The way I am trying to get it to work is a higher bonus with larger amount of health missing. However it is working the opposite of the desired effect. It gives me a -bonus that scales with missing health.

I am using add param script

EDIT! I got it!

<ft: add_param atk -((100-(((mhp-hp)*100)/mhp)*(0.1*atk))/100)>

Why does it have to be so confusing!
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
Well. To your first point in your original post: 

I am trying to create a formula to which involves my missing health, However whenever I use % it just acts like a subtraction example 420%320=100. Whenever I use / it drops anything <1. So I am finding it impossible to create anything based off my missing health. So I have gone to ridiculously confusing measures to get around this and it still doesn't work.
The modulous ( % ) in scripts means 'the remainder of' in your example, 100 is correct. 420 / 320 has a remainder of 100. It's not incorrect, it's just the same as subtraction. Division ( / ) will only give you a whole number. In the case of 420 / 320, this will only be 1. To get a decimal, you'll need to do 420/320.to_f + (420%320)/320. This should give you the normal decimal form that you were probably expecting, 1.3125.

As to the point about the other formula: 

<ft: add_param atk (100-(((mhp-hp)*100)/mhp)*(0.1*atk))/100>

If im at 100% HP mhp - hp = 0 so 0/ anything * anything should still be 0 and it should return as 0 but it doesnt even do that. This is the most frustrating thing. I don't know what to do at this point.
I explained in my earlier post as to why this comes out as 1 when you're at full health. The formula will evaluate (((mhp-hp)*100)/mhp)*(0.1*atk)) first, which will become 0 at full health. This leaves you with (100 - 0) / 100, which is the same as 100 / 100, which gives you your result of 1.

For your final point:

How do I stop it from throwing out results that <1!?
I'm not sure if you're referring to the damage formula that evaluates to 1, or the difference in % and / that you were also experiencing.
 
Last edited by a moderator:

ajilejay

Veteran
Veteran
Joined
Jul 17, 2013
Messages
64
Reaction score
0
First Language
English
Primarily Uses
Well. To your first point in your original post: 

The modulous ( % ) in scripts means 'the remainder of' in your example, 100 is correct. 420 / 320 has a remainder of 100. It's not incorrect, it's just the same as subtraction. Division ( / ) will only give you a whole number. In the case of 420 / 320, this will only be 1. To get a decimal, you'll need to do 420/320.to_f + (420%320)/320. This should give you the normal decimal form that you were probably expecting, 1.3125.

As to the point about the other formula: 

I explained in my earlier post as to why this comes out as 1 when you're at full health. The formula will evaluate (((mhp-hp)*100)/mhp)*(0.1*atk)) first, which will become 0 at full health. This leaves you with (100 - 0) / 100, which is the same as 100 / 100, which gives you your result of 1.

For your final point:

I'm not sure if you're referring to the damage formula that evaluates to 1, or the difference in % and / that you were also experiencing.
thanks man I got it to work
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
No problem, I'm glad you got it to work. formulas can be a real pain sometimes. I once spent a few days looking at one, trying to make it work. It really was a simple fix, and I only rewrote it about three times. Then I never ended up using that script really, so yay for that >_> .
 

Fomar0153

Arkz
Restaff
Joined
Mar 13, 2012
Messages
1,327
Reaction score
473
First Language
English
Primarily Uses
RMMZ
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 Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,863
Messages
1,017,053
Members
137,571
Latest member
grr
Top