Problem with custom formula

Hello, I created a custom formula for the basic skill Attack.

I replace : a.atk * 4 - b.def * 2

by : (a.atk * 2 - b.def - b.agi / 2) * ((a.agi * a.level) / 256)

326489Capture.jpg


I created a table in Excel to simulate different possible cases : http://www.mediafire.com/download/apn0v37fuow9gqe/D%C3%A9g%C3%A2ts.xlsx

You can change the level in top left, attacker values in top and defender values in left.

I created a Monster Test with 1 in defense and 1 in agility.

227517Capture2.jpg


My actors are level 1, they have approximately 30 in attack and 20 in agility. According to the table, they should do between 2 and 10 damages but they do 0 damage. I don't know why. Can you help me, please ?
A problem could be this part:

(a.agi*a.level)/256

When both operands in a division are integers, the result will also be rounded to an integer, meaning that if (a.agi*a.level) is not at least 256 the result will get rounded down to 0. You can prevent that from happening by converting one of the operands into a float, for example by using 256.0 instead of 256.

As an alternative, you can minimize rounding errors by doing the division last by removing the (unnecessary) pair of brackets from around the section shown above.
Ok, I should do also for b.agi / 2 ? Replace by b.agi / 2.0 ?
Ok, I should do also for b.agi / 2 ? Replace by b.agi / 2.0 ?
It depends on the numbers - in most cases that would be no problem

If the value for AGI is for example 23, then AGI/2 would result in 11 instead of 11.5 - not a difference that would do much in most cases.

The other case is more critical because in the case of AGI*LVL <255 it would result in zero, for example AGI = 25, Level = 10, AGI*LVL/256 = 0.977 rounded down to 0 (zero) as a result.
Ok, thanks for your quicks answers.

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-custom-formula.39353/