• 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 causing this "Trick Room When Sent Out" Ability code to crash?

  • 428
    Posts
    5
    Years
    Code:
    BattleHandlers::AbilityOnSwitchIn.add(:TRICKSTER,
      proc { |ability,battler,battle|
          @battle.field.effects[PBEffects::TrickRoom] = 5
          @battle.pbDisplay(_INTL("{1} twisted the dimensions!",user.pbThis))
      }
    )

    This code should work. Probably. But instead, when a Pokemon with this ability is sent out, the game crashes and the error message says this:

    Code:
    [Pokémon Essentials version 19.1]
    [Generation 8 Project v1.1.0]
    [v19.1 Hotfixes 1.0.7]
    
    Exception: NoMethodError
    Message: undefined method `field' for nil:NilClass
    
    Backtrace:
    142:BattleHandlers_Abilities:2840:in `block in <main>'
    035:Event_Handlers:199:in `trigger'
    141:BattleHandlers:454:in `triggerAbilityOnSwitchIn'
    154:Battler_AbilityAndItem:14:in `pbEffectsOnSwitchIn'
    176:Battle_Action_Switching:312:in `block in pbOnActiveAll'
    176:Battle_Action_Switching:312:in `each'
    176:Battle_Action_Switching:312:in `pbOnActiveAll'
    173:Battle_StartAndEnd:301:in `pbStartBattleCore'
    173:Battle_StartAndEnd:258:in `pbStartBattle'
    230:Overworld_BattleStarting:291:in `block (2 levels) in pbWildBattleCore'

    Why does this happen? How can it be fixed?
     
    Notice the difference between the battle that you have in the proc definition and @battle you're trying to use. You don't have access to an instance variable @battle in that code context. Use the battle variable that comes from the proc arguments.
     
    This works now, anyone who wants to use it is free to use it.

    Code:
    BattleHandlers::AbilityOnSwitchIn.add(:TRICKSTER,
      proc { |ability,battler,battle|
          battle.field.effects[PBEffects::TrickRoom] = 5
          battle.pbDisplay(_INTL("{1} twisted the dimensions for 5 turns!",battler.pbThis))
      }
    )
     
    Last edited:
    Back
    Top