How i make this conditional branch work?

I want to do this:

Variable control : #0001 Variable 1=Random 0. .255
Variable control : #0002 Variable 2=((3*b.mhp-2*b.hp)*100)/3*b.mhp
If Variable 2<Variable 1

...

Else

...

The problem its the formula does nothing, so the conditional branch only gives me the first result. I dont know much about variables so i probably did something stupid. I used the script option since i didnt see anywhere else where i could input a math formula to calculate the variable value
@Draewin Are you sure you're only getting the first result, not the second? It seems like the math here would make Variable 2 always greater than Variable 1. Examples:

If target hp = mhp, then Variable 2 = (100 mhp)/3*mhp ...or 33.33333*mhp^2, which is a huge number! Put ( ) around your denominator to help.
If target hp = 0, then Variable 2 = 100*mhp^2, which is even bigger! Again...I think you need those ( ) around the denominator. Hope it helps! 🙂

Sincerely,
@Draewin Are you sure you're only getting the first result, not the second? It seems like the math here would make Variable 2 always greater than Variable 1. Examples:

If target hp = mhp, then Variable 2 = (100 mhp)/3*mhp ...or 33.33333*mhp^2, which is a huge number! Put ( ) around your denominator to help.
If target hp = 0, then Variable 2 = 100*mhp^2, which is even bigger! Again...I think you need those ( ) around the denominator. Hope it helps! 🙂

Sincerely,
I did some math to check it. If for example the maxhp and current hp is 45....

((3*45-2*45)*100)/(3*45)
((135-90)*100)/135
4500/135
Result: 33,33

But the variable 2 still seems to have greater value no matter the case. Idk if its the math or im no putting the formula in the right place
or im no putting the formula in the right place

Where are you putting the formula?

Please show a screenshot. Are "a" and "b" defined in the context of your formula?
@Draewin According to your example with parentheses all properly placed, yes the result should be 33,33... This should, of course, only be bigger than some of the range 0-255, so it should do one condition sometimes and the other sometimes as well. In this case, one condition will "win" only ~13,07% of the time...so it may not seem like it's working...but if you placed the parentheses in the code as recommended and keep trying, you should get the opposite result to appear...if not often. Let's see...what happens if the character takes damage? Example: MaxHP = 45 and HP = 10; then Variable2 = 11500/135 = 85,185185... This should produce the other effect ~33,4% of the time, so...more likely to see the other case happen faster with damage. Let us know what you find. :blink:

@Aloe Guvner Using the battle formulae built into the RPG Maker engine, "a" stands for the attacker's stat and "b" stands for the target's, so... b.mhp means use the value of the target's Max HP.
upload_2019-5-14_0-6-38.png


I think this doesnt go on script box but im no sure where else it can be

@Aloe Guvner
@Draewin Yeah...that could be your problem. Here's the ugly part...the best solution I have for you is to set up a series of variables using Game Data and build to the desired value for Calculation...but there's got to be a better way to get this formula stored in a variable. Not sure why I can't think of it... :headshake:

I mean...the best I got right now is:
Set a variable (say 0002 Part1) equal to Game Data: Enemy: Max HP.
Control variable 0002: Operation Multiply, Operand 3
Now set a variable (0003 Part2) equal to Game Data: Enemy: HP.
Control variable 0003: Operation Multiply, Operand 2
Now set your variable 0001 Calculation to Variable: 0002
Control variable 0001: Operation Subtract, Operand Variable 0003
Control variable 0001: Operation Multiply, Operand 100
Control variable 0001: Operation Divide, Operand 0002
So...8 lines of code to set one value in a variable...and using Game Data to get the Enemy Max HP and Enemy HP requires you to identify an Enemy by ID, so...not sure if this will work for you either...but hope it will. Keep plugging at it and keep us posted.

Sincerely,
@Draewin Yeah...that could be your problem. Here's the ugly part...the best solution I have for you is to set up a series of variables using Game Data and build to the desired value for Calculation...but there's got to be a better way to get this formula stored in a variable. Not sure why I can't think of it... :headshake:

I mean...the best I got right now is:
Set a variable (say 0002 Part1) equal to Game Data: Enemy: Max HP.
Control variable 0002: Operation Multiply, Operand 3
Now set a variable (0003 Part2) equal to Game Data: Enemy: HP.
Control variable 0003: Operation Multiply, Operand 2
Now set your variable 0001 Calculation to Variable: 0002
Control variable 0001: Operation Subtract, Operand Variable 0003
Control variable 0001: Operation Multiply, Operand 100
Control variable 0001: Operation Divide, Operand 0002
So...8 lines of code to set one value in a variable...and using Game Data to get the Enemy Max HP and Enemy HP requires you to identify an Enemy by ID, so...not sure if this will work for you either...but hope it will. Keep plugging at it and keep us posted.

Sincerely,
Thanks a lot. Maybe i haven't enough experience with the program to do it simple but I will try my best to make it work

Original thread: https://forums.rpgmakerweb.com/threads/how-i-make-this-conditional-branch-work.108987/