• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • 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?

429
Posts
4
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?
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • 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.
     
    429
    Posts
    4
    Years
  • 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