Help with a damage formula

I'm trying to make a skill for a character that works off "momentum." The basic idea is that a character can build momentum (agility buffs) with attacks, and then spend that momentum (remove agility buffs) on attacks that use agility in the damage formula. This is what I have:

dmg = a.agi * 5;  a.remove_Buff(6);  dmg;

but it results in Null damage and doesn't remove the buff. I'm sure I've made a mistake in the formula somewhere. Can anyone help?
Try putting the removal of the buff first, then the damage formula.  


Do you need "dmg =" and "dmg" around your formula?  I can't see why it wouldn't work without it, but I don't have access to Ace at the moment to check it out.
I tried it, but it doesn't work, with or without the extra tags. Order of operation is also important; I want the skill to do the buffed damage before the buff is removed.

Interestingly, I replaced "buff" with "state" and it works fine. It does the damage and removes the appropriate state. But I've seen other users use add/remove.buff in their formulas and get results.
Your formula is only off by a bit, but that's more than enough to cause it not to function. Try this:

Code:
dmg = a.agi * 5 ; a.remove_buff(6) ; dmg
Works perfectly! Thank you.

EDIT: Now I'm having trouble with the "add" formula. Your formula works fine as is, but as soon as I change "remove" to "add" and leave everything else same, the result is "NULL." Does add_buff requite a different formula?


EDIT2: Nevermind. Figured it out. Had to add the duration value after the buff ID no.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-a-damage-formula.68473/