• 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!
  • 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.

[Scripting Question] Pokemon who use attacks cause an error to happen!

Scraps The Man

Crystal Collector
  • 33
    Posts
    4
    Years
    • Seen Jun 19, 2024
    I am not quite sure what I did wrong exactly, but I will at least explain that this (seemingly) started happening after I added a new class for my moves. (one that changes typing based off of the user's type)

    How it happens:
    1. A pokemon will use an attack
    2. The error message below will appear
    3. The attack will be negated and will have never happened

    Error Message:

    [Pokémon Essentials version 17.2]
    Exception: TypeError
    Message: nil can't be coerced into Fixnum
    PokeBattle_Move:1132:in `*'
    PokeBattle_Move:1132:in `pbCalcDamage'
    PokeBattle_Move:1365:in `pbEffect'
    PokeBattle_Battler:2797:in `pbProcessMoveAgainstTarget'
    PokeBattle_Battler:2753:in `each'
    PokeBattle_Battler:2753:in `pbProcessMoveAgainstTarget'
    PokeBattle_Battler:3229:in `pbUseMove'
    PokeBattle_Battler:3209:in `loop'
    PokeBattle_Battler:3232:in `pbUseMove'
    PokeBattle_Battler:3430:in `pbProcessTurn'

    If you know any way to fix this please give me some pointers!
     
    Can we see the code for this new move?

    Sure thing. The code is this:

    ################################################################################
    # The move's type is based on the user's primary type. (???)
    ################################################################################
    class PokeBattle_Move_19C < PokeBattle_Move

    def pbBaseType(user)
    return user.pbTypes[0]
    end

    end
     
    Wait, your game is v17.2
    This is a v18 style move class, using a v18 exclusive method
    You want
    Code:
    ################################################################################
    # The move's type is based on the user's primary type. (???)
    ################################################################################
    class PokeBattle_Move_19C < PokeBattle_Move
      def pbModifyType(type,attacker,opponent)
        return attacker.type1
      end
    end

    But that doesn't really explain the crash since pbBaseType is never used (because it doesn't exist).

    Can you show what's on line 1132 of PokeBattle_Move and the lines around it? My clean copy of v17.2 points me to a random end, so I assume you've got some edits in there.
     
    Good to hear that you have at least the v17 fix. As for the code you wanted to see, here is #1129-1161 (if you need more just ask and I will happily send you it!)

    # Type effectiveness
    if (options&IGNOREPKMNTYPES)==0
    typemod=pbTypeModMessages(type,attacker,opponent)
    damage=(damage*typemod/8.0).round
    opponent.damagestate.typemod=typemod
    if typemod==0
    opponent.damagestate.calcdamage=0
    opponent.damagestate.critical=false
    return 0
    end
    else
    opponent.damagestate.typemod=8
    end
    # Burn
    if attacker.status==PBStatuses::BURN && pbIsPhysical?(type) &&
    !attacker.hasWorkingAbility(:GUTS) &&
    !(USENEWBATTLEMECHANICS && @function==0x7E) # Facade
    damage=(damage*0.5).round
    end
    # Make sure damage is at least 1
    damage=1 if damage<1
    # Final damage modifiers
    finaldamagemult=0x1000
    if !opponent.damagestate.critical && (options&NOREFLECT)==0 &&
    !attacker.hasWorkingAbility(:INFILTRATOR)
    # Reflect
    if opponent.pbOwnSide.effects[PBEffects::Reflect]>0 && pbIsPhysical?(type)
    if @battle.doublebattle
    finaldamagemult=(finaldamagemult*0.66).round
    else
    finaldamagemult=(finaldamagemult*0.5).round
    end
    end
     
    Good to hear that you have at least the v17 fix. As for the code you wanted to see, here is #1129-1161 (if you need more just ask and I will happily send you it!)

    so if I got this right, damage=(damage*typemod/8.0).round is 1132. Based off the error message, typemod is nil, which means your pbTypeModMessages probably returned something completely wrong, or I guess more accurately pbTypeModifier returned nil.
    I suppose compare those methods with a clean version of essentials, and double check any edits you may have made.
     
    so if I got this right, damage=(damage*typemod/8.0).round is 1132. Based off the error message, typemod is nil, which means your pbTypeModMessages probably returned something completely wrong, or I guess more accurately pbTypeModifier returned nil.
    I suppose compare those methods with a clean version of essentials, and double check any edits you may have made.

    As funny as it is, my script for PokeBattler_Move is just completely busted now and I have no idea how to fix it. Therefore, I am gonna just make the decision to move everything to v18 so I can have a better version AND figure out what went wrong step by step; There were quite a lot of things that I added to that script section that could have caused errors somehow. (Although I have no idea how since they worked perfectly before today...)
     
    Hey,
    sorry I sent you the wrong version of the script, didn't know you used version 17 of Essentials. But you're right, upgrading to the newer version makes this a lot easier in general. Be sure to ask if you need help. :)
    And another quick tip to triviliaze bug fixing for you later on. Mark every change you make to the clean essentials script. It really cuts down on the time looking for errors.
     
    Hey,
    sorry I sent you the wrong version of the script, didn't know you used version 17 of Essentials. But you're right, upgrading to the newer version makes this a lot easier in general. Be sure to ask if you need help. :)
    And another quick tip to triviliaze bug fixing for you later on. Mark every change you make to the clean essentials script. It really cuts down on the time looking for errors.

    No problemo, I should have stated what I was using. Thanks to using a method to what you said though, I was able to find out that the MAIN problem was a custom move that was supposed to work like "Freeze Dry" but be a psychic-type move that worked against steel types (metalbend). (and also a bunch of other things that just kinda gunked up my code)

    Therefore, I may just keep my things in v17 for now so I don't get discouraged when having to move all that I made just for a few new things.

    (Also if anyone knows how to fix the move here is the code)

    if @function==0x135 && !attacker.effects[PBEffects::Electrify] # Freeze-Dry
    mod1=4 if isConst?(otype1,PBTypes,:WATER)
    if isConst?(otype2,PBTypes,:WATER)
    mod2=(otype1==otype2) ? 2 : 4
    end
    if isConst?(otype3,PBTypes,:WATER)
    mod3=(otype1==otype3 || otype2==otype3) ? 2 : 4
    end
    end
    if isConst?(@id,PBmoves,:METALBEND) && !attacker.effects[PBEffects::Electrify] # METALBEND
    mod1=4 if isConst?(otype1,PBTypes,: STEEL)
    if isConst?(otype2,PBTypes,: STEEL)
    mod2=(otype1==otype2) ? 2 : 4
    end
    if isConst?(otype3,PBTypes,: STEEL)
    mod3=(otype1==otype3 || otype2==otype3) ? 2 : 4
    end
    end
    return mod1*mod2*mod3
    end

    (": STEEL" don't actually have a space between the "S" and the ":" it is just to stop an emote from appearing)
     
    Back
    Top