• 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.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Serena, Kris, Dawn, Red - which Pokémon protagonist is your favorite? Let us know by voting in our grand final favorite protagonist poll!
  • 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?

  • 413
    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