Damage + Add State in a damage formula

I literally just want to add a state AND do damage and the fact that I can't figure it out is driving me insane. Can someone explain what I'm doing wrong here? I feel insanely dumb.

b.def <= (Math.randomInt(20) + 1 + (Math.floor((a.atk - 10) / 2)) + 2) ? b.addState(2) ; Math.randomInt(7) + 2 + (Math.floor((a.atk - 10) /2)) : 0 ;
Hi there!
Why do you have to add the state using a formula?
Because you can add a state using a trait

Weapons and armors:
1646901883079.png


Or using skill:
1646901953146.png


[EDIT]

Also, there is a syntax error in your formula.
Below the red mark is your formula and above is the same formula, but write in another way:
1646902297240.png


So maybe you can use that:
if(b.def <= (Math.randomInt(20) + 1 + (Math.floor((a.atk - 10) / 2)) + 2)){b.addState(2);return Math.randomInt(7) + 2 + (Math.floor((a.atk - 10) /2));}else{return 0;}
Hi there!
Why do you have to add the state using a formula?
Because you can add a state using a trait

Weapons and armors:
View attachment 219214

Or using skill:
View attachment 219215
It's because I have a custom system for resisting states but I managed to figure it out a few hours after posting this with this excessively long damage formula:

if (b.def <= (Math.randomInt(20) + 1 + (Math.floor((a.atk - 10) / 2)) + 2)) { if (10 > (Math.randomInt(20) + 1 + (Math.floor((b.luk - 10) / 2)))) { b.addState(2); } else { 0 ;} ; Math.randomInt(7) + 2 + (Math.floor((a.atk - 10) /2)); } else { 0; }

this is basically a damage formula that mimics the effect of rolling a d20 to hit and then on hit doing the damage AND the target needs to make a d20 roll to resist getting the state, all with appropriate modifiers.

Original thread: https://forums.rpgmakerweb.com/threads/damage-add-state-in-a-damage-formula.145611/