• 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] Game-crashing error every time a super-effective move is used? I think this code is the problem, how do I fix it?

  • 428
    Posts
    5
    Years
    [Pokémon Essentials version 19.1]
    [Generation 8 Project v1.1.0]
    [v19.1 Hotfixes 1.0.7]

    Exception: NameError
    Message: undefined local variable or method `b' for #<PokeBattle_Move_000>

    Backtrace:
    163:Move_Usage_Calculations:525:in `pbAdditionalEffectChance'
    155:Battler_UseMove:722:in `block in pbProcessMoveHit'
    155:Battler_UseMove:720:in `each'
    155:Battler_UseMove:720:in `pbProcessMoveHit'
    155:Battler_UseMove:433:in `block in pbUseMove'
    155:Battler_UseMove:431:in `each'
    155:Battler_UseMove:431:in `pbUseMove'
    155:Battler_UseMove:60:in `block in pbProcessTurn'
    012:PBDebug:6:in `logonerr'
    155:Battler_UseMove:59:in `pbProcessTurn'

    I started getting these crashes upon using super-effective moves after I made the Random Effect Chance and Serene Grace code into this:

    def pbAdditionalEffectChance(user,target,effectChance=0)
    return 0 if target.hasActiveAbility?(:SHIELDDUST) && [email protected]
    ret = (effectChance>0) ? effectChance : @addlEffect
    if Settings::MECHANICS_GENERATION >= 6 || @function != "0A4" # Secret Power
    ret = 100 if user.hasActiveAbility?(:SERENEGRACE)
    end
    ret = 100 if Effectiveness.super_effective?(b.damageState.typeMod);
    return ret
    ret = 100 if $DEBUG && Input.press?(Input::CTRL)
    return ret
    end

    My goal is:
    For randomly-happening optional effects to never trigger, unless it is an optional effect of a move that was super-effective, then the activation chance should be guaranteed at 100%. Serene Grace should also guarantee 100% optional effect chance.
     
    Last edited:
    Seems like you copy/pasted some code from somewhere but didn't change the names of the variables.

    This line introduces the problem:
    Code:
          ret = 100 if Effectiveness.super_effective?(b.damageState.typeMod);
    First, no need for ";" at the end of the line, it's Ruby, not C++ ^^
    Second, "b" is undefined. According to what you describe

    For randomly-happening optional effects to never trigger, unless it is an optional effect of a move that was super-effective, then the activation chance should be guaranteed at 100%. Serene Grace should also guarantee 100% optional effect chance.

    the "b" should be replaced with "target".

    Code:
          ret = 100 if Effectiveness.super_effective?(target.damageState.typeMod);
     
    Does this work?

    def pbAdditionalEffectChance(user,target,effectChance=0)
    return 0 if target.hasActiveAbility?(:SHIELDDUST) && [email protected]
    ret = (effectChance>0) ? effectChance : @addlEffect
    if Settings::MECHANICS_GENERATION >= 6 || @function != "0A4" # Secret Power
    ret = 100 if user.hasActiveAbility?(:SERENEGRACE)
    end
    ret = 100 if Effectiveness.super_effective?(target.damageState.typeMod)
    return ret
    ret = 100 if $DEBUG && Input.press?(Input::CTRL)
    return ret
    end

    def pbFlinchChance(user,target)
    ret = 100 if Effectiveness.super_effective?(target.damageState.typeMod)
    else
    ret = 0
    return ret
    end
    end
     
    Last edited:
    Does this work?

    It should work.
    But next time, please put your code inside SPOILER and CODE, just like this:

    Spoiler:
     
    I'm sorry, the code gave me a new error that says "Else without rescue is useless". The line number it mentions is the "else" in that code under "ret = 100 if".
     
    I'm sorry, the code gave me a new error that says "Else without rescue is useless". The line number it mentions is the "else" in that code under "ret = 100 if".

    My bad, I didn't read the second function because I found the error in the first one ^^
    The error was that you were confusing:

    Code:
    if <some condition>
      <some code 1>
    else
      <some code 2>
    end

    with:

    Code:
    <some code 1> if <some condition>

    Actually both are somewhat equivalent, but the logic, here, is:

    Code:
    <some default value>
    <a specific value> if <some condition>

    I also fixed the indent to be more readable:

    Spoiler:
     
    Back
    Top