Creating an "if" statement formula that applies damage and a state?

● ARCHIVED · READ-ONLY
Started by Papillon 5 posts View original ↗
  1. Hi there.
    I'm currently trying to create a damage formula which checks if an enemy has a state and applies damage and a another state depending on if it's applied.
    Problem is it always returns 0 damage so long as addState is in the code.
    I've tried
    Code:
    if ( b.isStateAffected(40) ) { a.atk * 1.25; b.addState(41); } else { a.atk * 0.75; }
    and
    Code:
    b.isStateAffected(40) ? b.addState(41) ; a.atk * 1.25: a.atk * 0.75
    and different variations of these but they always return 0 damage.
    Can anyone point out what I'm doing wrong?
  2. That's because return value of an eval is the return value of last legit code. Meaning that if b is affected by the state, the damage is equal to 0, because addState doesn't have any return value.

    As for the second thing, that's just wrong, because
    premise ? happenIfTrue : happenIfFalse
    accepts only one line, so you can't use ; there.
  3. Poryg said:
    That's because return value of an eval is the return value of last legit code. Meaning that if b is affected by the state, the damage is equal to 0, because addState doesn't have any return value.

    As for the second thing, that's just wrong, because
    premise ? happenIfTrue : happenIfFalse
    accepts only one line, so you can't use ; there.
    I knew I was doing something completely wrong. Is what I'm trying to do possible, or would this be something I'd have to get a plugin for?
    Normally I'd just apply the state with the Effects menu but that would just allow the attack to apply both the state while still doing the lower damage.
    Also sorry for the sloppy coding. I haven't touched Javascript in quite a while.
  4. The first case should work, just swap the state add with the damage calculation in the true case.
  5. Poryg said:
    The first case should work, just swap the state add with the damage calculation in the true case.
    Bloody hell I'm stupid.
    It works now.
    Thank you for the help!