Damage formula with a state condition

Hi. I've searched over the whole forum for this, but was unable to find a solution that worked. I've created a skill that does more damage to the enemy if the enemy is stunned.

This is what I've put into the damage formula:

b.state(8)? a.atk * 7 - b.def * 2 : a.atk * 5 - b.def * 2

However, whenever I test it in the game, it always inflicts 0 damage (regardless of whether the enemy has the state on or not). I've checked enemy stats and all, so it shouldn't be dealing 0 damage, unless my formula is wrong. I tried doing it via other ways, but all those ways give me a syntax error. Would anyone be able to advise what I'm missing here?

Thanks.
if b.state?(x); damage formula 1; else; damage formula 2; end

That should work =D

Not nearly as efficiently in terms of character but it gets the job done.

~ Dinhbat

EDIT: 

Oh I looked closer and saw the problem... you forgot a question mark after b.state.

This should work correctly as well:

b.state?(8)? a.atk * 7 - b.def * 2 : a.atk * 5 - b.def * 2
Ah fantastic. That worked perfectly. Thank you.

 What about adding a state to the user after they've performed the special attack? At the moment I have this:

a.atk * 8 - b.def * 2; a.add_state(12)

And although the state gets applied, the damage dealt ends up as 0.
add the state before the damage... damage should always be the last part
Worked perfectly once more. Thank you both. I'm still learning to grasp some of the more complex features of the damage formula. Glad to have these ones cleared up.

Original thread: https://forums.rpgmakerweb.com/threads/damage-formula-with-a-state-condition.26218/