[ACE] Issues with an Enemy Reactions Snippet

I've been having problems with this script snippet I devised for a friend.  Said friend wanted enemies to react to getting hit with specific elements, but only if they dealt damage.  So I came up with the idea of making them react to a switch that's thrown in response to a spell dealing damage.

I've tested it, and found that the snippet nulls instead the damage outright.  Can someone help me figure out what's wrong?

 

class Game_Battler < Game_BattlerBase  def no_damage?(a, b, base_dmg, atk_mod, def_mod, switch_id)    c = ( base_dmg + ( a.atk * atk_mod ) - ( b.def * def_mod ) )    if c > 0      $game_switches[switch_id] == 1      return c    else      return 0    end  endendScript call in damage formula: 

Code:
c = no_damage(a, b, int, int, int, int); c
Bump.
CtelinAjira, please do not bump your topic unless it has been 72 hours later since your last post. You can review our forum rules here. Thank you.

Not only do you have to take into account differing time zones, different work/leisure schedules and the fact that everyone answering here is doing it in their free time and have other commitments as well, today is also the last day of IGMC and a lot of people are having to focus on that.  The 72 hour buffer is there for a good reason.
I'm pretty sure the $game_switches[id] returns a true/false.

$game_switches[switch_id] == 1 this line would then do absolutely nothing, and in Ruby, quite possibly return the nothing.  If you said, $game_switches[switch_id] = 1, you would still be doing it wrong I think.

$game_switches[switch_id] = true, would be correct.
I'm pretty sure the $game_switches[id] returns a true/false.

$game_switches[switch_id] == 1 this line would then do absolutely nothing, and in Ruby, quite possibly return the nothing.  If you said, $game_switches[switch_id] = 1, you would still be doing it wrong I think.

$game_switches[switch_id] = true, would be correct.
I've made these changes, and it still doesn't do everything just right.  It's still nulling the damage.

Code:
class Game_Battler < Game_BattlerBase  def no_damage?(a, b, base_dmg, atk_mod, def_mod, switch_id)    c = ( base_dmg + ( a.atk * atk_mod ) - ( b.def * def_mod ) )    if c > 0      $game_switches[switch_id] = true      return c    else      return 0    end  endend
try 

Code:
c = a.no_damage?(a, b, int, int, int, int); c
try 

c = a.no_damage?(a, b, int, int, int, int); c
Tried it.  it's still failing.  This is confounding me.
Bump
I should suppose you changed those 'int' to some value, right?
I should suppose you changed those 'int' to some value, right?
Yes I did.
bump
bump
Add a 'p c' line above the 'if c > 0' line (without the apostrophes).


Observe your console when you use a skill, it will print out the result of your formula.


If that formula is 0 or lower (and it most probably is), than your formula returns a lower value than you expect, which is possible if the enemy's DEF is high, and/or if the actor's ATT is too low, depending on the modifiers you use.


But if you simply write this into the damage box (random arguments):

no_damage?(a, b, 100, 1.5, 1.2, 888)It will not run, because the damage formula itself is run on the RPG::UsableItem:😀amage instance, and NOT on the battler. But that class got no 'no_damage?' method defined, so it returns 0 with a rescue instead of crashing. You can test this with the 'p c' line I mentioned above. The console will not print anything when you use the skill in this case.
But if you write this:

a.no_damage?(a, b, 100, 1.5, 1.2, 888)Now, this will be run on Game_Battler, so it will not fail, but it can still return a value lower than 0. You will see the result of the damage formula printed out in this case, because the method has been executed.
Also you don't need to write the 'c = formula; c' thing. You method returns a number already, so no need to store and return that number again.

Original thread: https://forums.rpgmakerweb.com/threads/ace-issues-with-an-enemy-reactions-snippet.43324/