• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Trading Card Game 2 protagonist in the poll by clicking here.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Error] What's wrong with my "Only trigger additional move effect if the move is SuperEffective on its target" code?

  • 428
    Posts
    5
    Years
    Hello, I'd like to remove an element of RNG from the game by making the optional effects of some moves (For example, Psychic and its chance to reduce the foe's Special Defense stat) only trigger when the move is super effective.

    Code:
        # Additional effect ON SUPER EFFECTIVES ONLY
        if !user.hasActiveAbility?(:SHEERFORCE)
          targets.each do |b|
            next if b.damageState.calcDamage>=0 && Effectiveness.super_effective?(target.damageState.typeMod)
              move.pbAdditionalEffect(user,b)
          end
        end

    What am I doing wrong? When I attack a Pokemon Super Effectively, I get an error that says

    Code:
    Exception `NameError' at 155:Battler_UseMove:721 - undefined local variable or method `target' for #<PokeBattle_Battler>
     
    Back
    Top