• 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] Can't Get Past Error Message

  • 19
    Posts
    1
    Years
    • Age 21
    • He/Him
    • Seen yesterday
    So I'm trying to create this new ability called Celestial Guard, where basically it's Magic Bounce but it reflects projectile or bomb type moves back at the opponent. I tried to copy the code for Magic Bounce, but this error message keeps popping up.

    Exception `SyntaxError' at -e - 166:Battler_UseMove:509: dynamic constant assignment
    CelestialGuarder = -1
    ^~~~~~~~~~~~~~~~

    -e:in `eval': 166:Battler_UseMove:509: dynamic constant assignment
    CelestialGuarder = -1
    ^~~~~~~~~~~~~~~~
    (SyntaxError)

    Here's the code if you need to see it.

    Code:
        magicCoater  = -1
        magicBouncer = -1
        if targets.length == 0 && move.pbTarget(user).num_targets > 0 && !move.worksWithNoTargets?
          # def pbFindTargets should have found a target(s), but it didn't because
          # they were all fainted
          # All target types except: None, User, UserSide, FoeSide, BothSides
          @battle.pbDisplay(_INTL("But there was no target..."))
          user.lastMoveFailed = true
        else   # We have targets, or move doesn't use targets
          # Reset whole damage state, perform various success checks (not accuracy)
          @battle.allBattlers.each do |b|
            b.droppedBelowHalfHP = false
            b.statsDropped = false
          end
          targets.each do |b|
            b.damageState.reset
            next if pbSuccessCheckAgainstTarget(move, user, b, targets)
            b.damageState.unaffected = true
          end
          # Magic Coat/Magic Bounce checks (for moves which don't target Pokémon)
          if targets.length == 0 && move.statusMove? && move.canMagicCoat?
            @battle.pbPriority(true).each do |b|
              next if b.fainted? || !b.opposes?(user)
              next if b.semiInvulnerable?
              if b.effects[PBEffects::MagicCoat]
                magicCoater = b.index
                b.effects[PBEffects::MagicCoat] = false
                break
              elsif b.hasActiveAbility?(:MAGICBOUNCE) && [email protected] &&
                    !b.effects[PBEffects::MagicBounce]
                magicBouncer = b.index
                b.effects[PBEffects::MagicBounce] = true
                break
              end
            end
          end
          # Get the number of hits
          numHits = move.pbNumHits(user, targets)
          # Process each hit in turn
          realNumHits = 0
          numHits.times do |i|
            break if magicCoater >= 0 || magicBouncer >= 0
            success = pbProcessMoveHit(move, user, targets, i, skipAccuracyCheck)
            if !success
              if i == 0 && targets.length > 0
                hasFailed = false
                targets.each do |t|
                  next if t.damageState.protected
                  hasFailed = t.damageState.unaffected
                  break if !t.damageState.unaffected
                end
                user.lastMoveFailed = hasFailed
              end
              break
            end
            realNumHits += 1
            break if user.fainted?
            break if [:SLEEP, :FROZEN].include?(user.status)
            # NOTE: If a multi-hit move becomes disabled partway through doing those
            #       hits (e.g. by Cursed Body), the rest of the hits continue as
            #       normal.
            break if targets.none? { |t| !t.fainted? }   # All targets are fainted
          end
          # Battle Arena only - attack is successful
          @battle.successStates[user.index].useState = 2
          if targets.length > 0
            @battle.successStates[user.index].typeMod = 0
            targets.each do |b|
              next if b.damageState.unaffected
              @battle.successStates[user.index].typeMod += b.damageState.typeMod
            end
          end
          # Effectiveness message for multi-hit moves
          # NOTE: No move is both multi-hit and multi-target, and the messages below
          #       aren't quite right for such a hypothetical move.
          if numHits > 1
            if move.damagingMove?
              targets.each do |b|
                next if b.damageState.unaffected || b.damageState.substitute
                move.pbEffectivenessMessage(user, b, targets.length)
              end
            end
            if realNumHits == 1
              @battle.pbDisplay(_INTL("Hit 1 time!"))
            elsif realNumHits > 1
              @battle.pbDisplay(_INTL("Hit {1} times!", realNumHits))
            end
          end
          # Magic Coat's bouncing back (move has targets)
          targets.each do |b|
            next if b.fainted?
            next if !b.damageState.magicCoat && !b.damageState.magicBounce
            @battle.pbShowAbilitySplash(b) if b.damageState.magicBounce
            @battle.pbDisplay(_INTL("{1} bounced the {2} back!", b.pbThis, move.name))
            @battle.pbHideAbilitySplash(b) if b.damageState.magicBounce
            newChoice = choice.clone
            newChoice[3] = user.index
            newTargets = pbFindTargets(newChoice, move, b)
            newTargets = pbChangeTargets(move, b, newTargets)
            success = false
            if !move.pbMoveFailed?(b, newTargets)
              newTargets.each_with_index do |newTarget, idx|
                if pbSuccessCheckAgainstTarget(move, b, newTarget, newTargets)
                  success = true
                  next
                end
                newTargets[idx] = nil
              end
              newTargets.compact!
            end
            pbProcessMoveHit(move, b, newTargets, 0, false) if success
            b.lastMoveFailed = true if !success
            targets.each { |otherB| otherB.pbFaint if otherB&.fainted? }
            user.pbFaint if user.fainted?
          end
          # Magic Coat's bouncing back (move has no targets)
          if magicCoater >= 0 || magicBouncer >= 0
            mc = @battle.battlers[(magicCoater >= 0) ? magicCoater : magicBouncer]
            if !mc.fainted?
              user.lastMoveFailed = true
              @battle.pbShowAbilitySplash(mc) if magicBouncer >= 0
              @battle.pbDisplay(_INTL("{1} bounced the {2} back!", mc.pbThis, move.name))
              @battle.pbHideAbilitySplash(mc) if magicBouncer >= 0
              success = false
              if !move.pbMoveFailed?(mc, [])
                success = pbProcessMoveHit(move, mc, [], 0, false)
              end
              mc.lastMoveFailed = true if !success
              targets.each { |b| b.pbFaint if b&.fainted? }
              user.pbFaint if user.fainted?
            end
          end
          # Move-specific effects after all hits
          targets.each { |b| move.pbEffectAfterAllHits(user, b) }
          # Faint if 0 HP
          targets.each { |b| b.pbFaint if b&.fainted? }
          user.pbFaint if user.fainted?
          # External/general effects after all hits. Eject Button, Shell Bell, etc.
          pbEffectsAfterMove(user, targets, move, realNumHits)
          @battle.allBattlers.each do |b|
            b.droppedBelowHalfHP = false
            b.statsDropped = false
          end
        end
        CelestialGuarder = -1
        if targets.length == 0 && move.pbTarget(user).num_targets > 0 && !move.worksWithNoTargets?
          # def pbFindTargets should have found a target(s), but it didn't because
          # they were all fainted
          # All target types except: None, User, UserSide, FoeSide, BothSides
          @battle.pbDisplay(_INTL("But there was no target..."))
          user.lastMoveFailed = true
        else   # We have targets, or move doesn't use targets
          # Reset whole damage state, perform various success checks (not accuracy)
          @battle.allBattlers.each do |b|
            b.droppedBelowHalfHP = false
            b.statsDropped = false
          end
          targets.each do |b|
            b.damageState.reset
            next if pbSuccessCheckAgainstTarget(move, user, b, targets)
            b.damageState.unaffected = true
          end
          # Magic Coat/Magic Bounce checks (for moves which don't target Pokémon)
          if targets.length == 0 && move.bombMove? 
            @battle.pbPriority(true).each do |b|
              next if b.fainted? || !b.opposes?(user)
              next if b.semiInvulnerable?
              if b.hasActiveAbility?(:CELESTIALGUARD) && [email protected] &&
                !b.effects[PBEffects::CelestialGuard]
                magicBouncer = b.index
                b.effects[PBEffects::CelestialGuard] = true
                break
              end
            end
          end
          # Get the number of hits
          numHits = move.pbNumHits(user, targets)
          # Process each hit in turn
          realNumHits = 0
          numHits.times do |i|
            break if CelestialGuarder >= 0
            success = pbProcessMoveHit(move, user, targets, i, skipAccuracyCheck)
            if !success
              if i == 0 && targets.length > 0
                hasFailed = false
                targets.each do |t|
                  next if t.damageState.protected
                  hasFailed = t.damageState.unaffected
                  break if !t.damageState.unaffected
                end
                user.lastMoveFailed = hasFailed
              end
              break
            end
            realNumHits += 1
            break if user.fainted?
            break if [:SLEEP, :FROZEN].include?(user.status)
            # NOTE: If a multi-hit move becomes disabled partway through doing those
            #       hits (e.g. by Cursed Body), the rest of the hits continue as
            #       normal.
            break if targets.none? { |t| !t.fainted? }   # All targets are fainted
          end
          # Battle Arena only - attack is successful
          @battle.successStates[user.index].useState = 2
          if targets.length > 0
            @battle.successStates[user.index].typeMod = 0
            targets.each do |b|
              next if b.damageState.unaffected
              @battle.successStates[user.index].typeMod += b.damageState.typeMod
            end
          end
          # Effectiveness message for multi-hit moves
          # NOTE: No move is both multi-hit and multi-target, and the messages below
          #       aren't quite right for such a hypothetical move.
          if numHits > 1
            if move.damagingMove?
              targets.each do |b|
                next if b.damageState.unaffected || b.damageState.substitute
                move.pbEffectivenessMessage(user, b, targets.length)
              end
            end
            if realNumHits == 1
              @battle.pbDisplay(_INTL("Hit 1 time!"))
            elsif realNumHits > 1
              @battle.pbDisplay(_INTL("Hit {1} times!", realNumHits))
            end
          end
          # Magic Coat's bouncing back (move has targets)
          targets.each do |b|
            next if b.fainted?
            next if !b.damageState.magicCoat && !b.damageState.celestialGuard
            @battle.pbShowAbilitySplash(b) if b.damageState.celestialGuard
            @battle.pbDisplay(_INTL("{1} bounced the {2} back!", b.pbThis, move.name))
            @battle.pbHideAbilitySplash(b) if b.damageState.celestialGuard
            newChoice = choice.clone
            newChoice[3] = user.index
            newTargets = pbFindTargets(newChoice, move, b)
            newTargets = pbChangeTargets(move, b, newTargets)
            success = false
            if !move.pbMoveFailed?(b, newTargets)
              newTargets.each_with_index do |newTarget, idx|
                if pbSuccessCheckAgainstTarget(move, b, newTarget, newTargets)
                  success = true
                  next
                end
                newTargets[idx] = nil
              end
              newTargets.compact!
            end
            pbProcessMoveHit(move, b, newTargets, 0, false) if success
            b.lastMoveFailed = true if !success
            targets.each { |otherB| otherB.pbFaint if otherB&.fainted? }
            user.pbFaint if user.fainted?
          end
          # Magic Coat's bouncing back (move has no targets)
          if CelestialGuarder >= 0
            if !mc.fainted?
              user.lastMoveFailed = true
              @battle.pbShowAbilitySplash(mc) if CelestialGuarder >= 0
              @battle.pbDisplay(_INTL("{1} bounced the {2} back!", mc.pbThis, move.name))
              @battle.pbHideAbilitySplash(mc) if CelestialGuarder >= 0
              success = false
              if !move.pbMoveFailed?(mc, [])
                success = pbProcessMoveHit(move, mc, [], 0, false)
              end
              mc.lastMoveFailed = true if !success
              targets.each { |b| b.pbFaint if b&.fainted? }
              user.pbFaint if user.fainted?
            end
          end
          # Move-specific effects after all hits
          targets.each { |b| move.pbEffectAfterAllHits(user, b) }
          # Faint if 0 HP
          targets.each { |b| b.pbFaint if b&.fainted? }
          user.pbFaint if user.fainted?
          # External/general effects after all hits. Eject Button, Shell Bell, etc.
          pbEffectsAfterMove(user, targets, move, realNumHits)
          @battle.allBattlers.each do |b|
            b.droppedBelowHalfHP = false
            b.statsDropped = false
          end
        end

    I had trouble with this ability and also a new move for a while now, and I just wanted to get past it so I could play the game, but there was so much code that I didn't want to delete it all. I just now backed all the code up, but there's still a lot to delete. I just want to fix it now so I can move on.
     
  • 188
    Posts
    9
    Years
    • Seen May 16, 2024
    The program appears to be treating CelestialGuarder as a constant due to an initial capital letter. Most programmers use camel case for their variables.
     
  • 19
    Posts
    1
    Years
    • Age 21
    • He/Him
    • Seen yesterday
    The game is working again as usual, but for some reason, all moves are done twice in a row in one turn as if they're multi-hit. Like literally every move, including stuff like Defense Curl. Do you know what could be causing this, because error messages are no longer appearing.
     
  • 188
    Posts
    9
    Years
    • Seen May 16, 2024
    Well, you appear to have a second copy of the code after your Celestial Guard code. In place of your posted code in Battler_UseMoves, try this:
    Code:
        magicCoater  = -1
        magicBouncer = -1
        if targets.length == 0 && move.pbTarget(user).num_targets > 0 && !move.worksWithNoTargets?
          # def pbFindTargets should have found a target(s), but it didn't because
          # they were all fainted
          # All target types except: None, User, UserSide, FoeSide, BothSides
          @battle.pbDisplay(_INTL("But there was no target..."))
          user.lastMoveFailed = true
        else   # We have targets, or move doesn't use targets
          # Reset whole damage state, perform various success checks (not accuracy)
          @battle.allBattlers.each do |b|
            b.droppedBelowHalfHP = false
            b.statsDropped = false
          end
          targets.each do |b|
            b.damageState.reset
            next if pbSuccessCheckAgainstTarget(move, user, b, targets)
            b.damageState.unaffected = true
          end
          # Magic Coat/Magic Bounce checks (for moves which don't target Pokémon)
          if targets.length == 0 && move.statusMove? && move.canMagicCoat?
            @battle.pbPriority(true).each do |b|
              next if b.fainted? || !b.opposes?(user)
              next if b.semiInvulnerable?
              if b.effects[PBEffects::MagicCoat]
                magicCoater = b.index
                b.effects[PBEffects::MagicCoat] = false
                break
              elsif b.hasActiveAbility?(:MAGICBOUNCE) && [email protected] &&
                    !b.effects[PBEffects::MagicBounce]
                magicBouncer = b.index
                b.effects[PBEffects::MagicBounce] = true
                break
              end
            end
          end
          # Get the number of hits
          numHits = move.pbNumHits(user, targets)
          # Process each hit in turn
          realNumHits = 0
          numHits.times do |i|
            break if magicCoater >= 0 || magicBouncer >= 0
            success = pbProcessMoveHit(move, user, targets, i, skipAccuracyCheck)
            if !success
              if i == 0 && targets.length > 0
                hasFailed = false
                targets.each do |t|
                  next if t.damageState.protected
                  hasFailed = t.damageState.unaffected
                  break if !t.damageState.unaffected
                end
                user.lastMoveFailed = hasFailed
              end
              break
            end
            realNumHits += 1
            break if user.fainted?
            break if [:SLEEP, :FROZEN].include?(user.status)
            # NOTE: If a multi-hit move becomes disabled partway through doing those
            #       hits (e.g. by Cursed Body), the rest of the hits continue as
            #       normal.
            break if targets.none? { |t| !t.fainted? }   # All targets are fainted
          end
          # Battle Arena only - attack is successful
          @battle.successStates[user.index].useState = 2
          if targets.length > 0
            @battle.successStates[user.index].typeMod = 0
            targets.each do |b|
              next if b.damageState.unaffected
              @battle.successStates[user.index].typeMod += b.damageState.typeMod
            end
          end
          # Effectiveness message for multi-hit moves
          # NOTE: No move is both multi-hit and multi-target, and the messages below
          #       aren't quite right for such a hypothetical move.
          if numHits > 1
            if move.damagingMove?
              targets.each do |b|
                next if b.damageState.unaffected || b.damageState.substitute
                move.pbEffectivenessMessage(user, b, targets.length)
              end
            end
            if realNumHits == 1
              @battle.pbDisplay(_INTL("Hit 1 time!"))
            elsif realNumHits > 1
              @battle.pbDisplay(_INTL("Hit {1} times!", realNumHits))
            end
          end
          # Magic Coat's bouncing back (move has targets)
          targets.each do |b|
            next if b.fainted?
            next if !b.damageState.magicCoat && !b.damageState.magicBounce
            @battle.pbShowAbilitySplash(b) if b.damageState.magicBounce
            @battle.pbDisplay(_INTL("{1} bounced the {2} back!", b.pbThis, move.name))
            @battle.pbHideAbilitySplash(b) if b.damageState.magicBounce
            newChoice = choice.clone
            newChoice[3] = user.index
            newTargets = pbFindTargets(newChoice, move, b)
            newTargets = pbChangeTargets(move, b, newTargets)
            success = false
            if !move.pbMoveFailed?(b, newTargets)
              newTargets.each_with_index do |newTarget, idx|
                if pbSuccessCheckAgainstTarget(move, b, newTarget, newTargets)
                  success = true
                  next
                end
                newTargets[idx] = nil
              end
              newTargets.compact!
            end
            pbProcessMoveHit(move, b, newTargets, 0, false) if success
            b.lastMoveFailed = true if !success
            targets.each { |otherB| otherB.pbFaint if otherB&.fainted? }
            user.pbFaint if user.fainted?
          end
          # Magic Coat's bouncing back (move has no targets)
          if magicCoater >= 0 || magicBouncer >= 0
            mc = @battle.battlers[(magicCoater >= 0) ? magicCoater : magicBouncer]
            if !mc.fainted?
              user.lastMoveFailed = true
              @battle.pbShowAbilitySplash(mc) if magicBouncer >= 0
              @battle.pbDisplay(_INTL("{1} bounced the {2} back!", mc.pbThis, move.name))
              @battle.pbHideAbilitySplash(mc) if magicBouncer >= 0
              success = false
              if !move.pbMoveFailed?(mc, [])
                success = pbProcessMoveHit(move, mc, [], 0, false)
              end
              mc.lastMoveFailed = true if !success
              targets.each { |b| b.pbFaint if b&.fainted? }
              user.pbFaint if user.fainted?
            end
          end
    [COLOR="Red"]      # Celestial Guard's bouncing back
          targets.each do |b|
            next if b.fainted? || !b.damageState.celestialGuard
            @battle.pbShowAbilitySplash(b) if b.damageState.celestialGuard
            @battle.pbDisplay(_INTL("{1} bounced the {2} back!", b.pbThis, move.name))
            @battle.pbHideAbilitySplash(b) if b.damageState.celestialGuard
            newChoice = choice.clone
            newChoice[3] = user.index
            newTargets = pbFindTargets(newChoice, move, b)
            newTargets = pbChangeTargets(move, b, newTargets)
            success = false
            if !move.pbMoveFailed?(b, newTargets)
              newTargets.each_with_index do |newTarget, idx|
                if pbSuccessCheckAgainstTarget(move, b, newTarget, newTargets)
                  success = true
                  next
                end
                newTargets[idx] = nil
              end
              newTargets.compact!
            end
            pbProcessMoveHit(move, b, newTargets, 0, false) if success
            b.lastMoveFailed = true if !success
            targets.each { |otherB| otherB.pbFaint if otherB&.fainted? }
            user.pbFaint if user.fainted?
          end[/COLOR]

    Add this in Battle_DamageState:
    Code:
      attr_accessor :magicCoat
      attr_accessor :magicBounce
    [COLOR="Red"]  attr_accessor :celestialGuard[/COLOR]
      attr_accessor :totalHPLost     # Like hpLost, but cumulative over all hits
      attr_accessor :fainted         # Whether battler was knocked out by the move
    
      attr_accessor :missed          # Whether the move failed the accuracy check
      attr_accessor :affection_missed
      attr_accessor :invulnerable    # If the move missed due to two turn move invulnerability
      attr_accessor :calcDamage      # Calculated damage
      attr_accessor :hpLost          # HP lost by opponent, inc. HP lost by a substitute
      attr_accessor :critical        # Critical hit flag
      attr_accessor :affection_critical
      attr_accessor :substitute      # Whether a substitute took the damage
      attr_accessor :focusBand       # Focus Band used
      attr_accessor :focusSash       # Focus Sash used
      attr_accessor :sturdy          # Sturdy ability used
      attr_accessor :disguise        # Disguise ability used
      attr_accessor :iceFace         # Ice Face ability used
      attr_accessor :endured         # Damage was endured
      attr_accessor :affection_endured
      attr_accessor :berryWeakened   # Whether a type-resisting berry was used
    
      def initialize; reset; end
    
      def reset
        @typeMod          = Effectiveness::INEFFECTIVE
        @unaffected       = false
        @protected        = false
        @missed           = false
        @affection_missed = false
        @invulnerable     = false
        @magicCoat        = false
        @magicBounce      = false
    [COLOR="Red"]    @celestialGuard   = false[/COLOR]
        @totalHPLost      = 0
        @fainted          = false
        resetPerHit
      end

    Add this to Battler_UseMoveSuccessCheck:
    Code:
        # Magic Coat/Magic Bounce
        if move.statusMove? && move.canMagicCoat? && !target.semiInvulnerable? && target.opposes?(user)
          if target.effects[PBEffects::MagicCoat]
            target.damageState.magicCoat = true
            target.effects[PBEffects::MagicCoat] = false
            return false
          end
          if target.hasActiveAbility?(:MAGICBOUNCE) && [email protected] &&
             !target.effects[PBEffects::MagicBounce]
            target.damageState.magicBounce = true
            target.effects[PBEffects::MagicBounce] = true
            return false
          end
        end
    [COLOR="Red"]    # Celestial Guard
        if target.hasActiveAbility?(:CELESTIALGUARD) && [email protected] &&
             move.bombMove?
            target.damageState.celestialGuard = true
            return false
          end
        end[/COLOR]
     
    Back
    Top