I can't figure out why this damage formula is resulting in 0

So the formula I'm using is:
(a.atk * a.atk - b.def * (b.def / 6)) / (v[18] + 1)
everything was working fine with this formula until I added / (v[18] + 1) at the end but now its resulting in 0 but if the variable is 0 it should still be divided by one so until the variable is changed all damage should be the same. This is my first time using a variable in a damage formula so something probably isn't typed right I'm guessing.
I don't believe you can call variables that way in damage formulas.
Try $gameVariables.value(18) instead.
What happens when you change the variable?

EDIT: Ninja'd by TWings; try that first
v[x] is valid in a damage formula, but it's an "unsafe" way to retrieve the value. If you haven't assigned a value to variable 18 beforehand, then v[18] will return undefined. By contrast, $gameVariables.value(18) (like @TWings suggested) is "safe": it'll return 0 if the "real" value hasn't been defined yet. 😮‍💨

The damage formula has a safety catch: if the final result is non-numerical (e.g. undefined), it'll return zero. Hence, I think, your situation. 😅

(Generally speaking you'd set the variable value in advance; in that case this sort of thing isn't a problem.)
v[x] is valid in a damage formula, but it's an "unsafe" way to retrieve the value. If you haven't assigned a value to variable 18 beforehand, then v[18] will return undefined. By contrast, $gameVariables.value(18) (like @TWings suggested) is "safe": it'll return 0 if the "real" value hasn't been defined yet. 😮‍💨

The damage formula has a safety catch: if the final result is non-numerical (e.g. undefined), it'll return zero. Hence, I think, your situation. 😅

(Generally speaking you'd set the variable value in advance; in that case this sort of thing isn't a problem.)
That's my problem it works again if i define the variable as 0. I just figured that the variables were set to 0 until said otherwise. That makes it a little harder for testing, but at least it's all working again. Thank you!
If your formula results in something between 0 and 1, it will return 0.

When you use $gameVariables.value(18) it will return 0 if it's not defined because the value() function does that check. But I think when you use v[18] in the damage formula, it doesn't do the same thing, because it's accessing the actual data array without going through the function that does the test for an existing value.

You could try this:

(a.atk * a.atk - b.def * (b.def / 6)) / ((v[18] || 0) + 1)

Original thread: https://forums.rpgmakerweb.com/threads/i-cant-figure-out-why-this-damage-formula-is-resulting-in-0.119152/