• 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.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Serena, Kris, Dawn, Red - which Pokémon protagonist is your favorite? Let us know by voting in our grand final favorite protagonist poll!
  • PokéCommunity supports the Stop Killing Games movement. If you're a resident of the UK or EU, consider signing one of the petitions to stop publishers from destroying games. Click here for more information!
  • 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] Why is my Caltrops code consistently causing crashes during battle whenever any Pokemon tries using them?

  • 413
    Posts
    5
    Years
    Code:
    Battle::ItemEffects::OnSwitchIn.add(:CALTROPS,
      proc { |item, user, battler, target, move, battle|
      next    if user.pbOpposingSide.effects[PBEffects::Spikes] >= 3
          user.pbOpposingSide.effects[PBEffects::Spikes] += 1
        battler.pbConsumeItem
      }
    )

    Code:
    Battle::ItemEffects::OnSwitchIn.add(:CALTROPS,
      proc { |item, battler, battle|
      next    if user.pbOpposingSide.effects[PBEffects::Spikes] >= 3
          user.pbOpposingSide.effects[PBEffects::Spikes] += 1
        battle.pbDisplay(_INTL("{1} scatters Caltrops on the foe's side of the field!",
           battler.pbThis, battler.itemName))
      }
    )

    Which version of this code is closer to correct, and what will fix it?

    The goal is for the held item to use Spikes once, and then consume itself, when the Pokemon holding it is sent out.

    Sometimes the error message claims the engine doesn't know what "User" or "Battle" or "Battler" is, and sometimes it claims to not know what "pbOpposingSide" or "PBEffects::Spikes" is.
     
    Last edited:
    The OnSwitchIn Item Effect proc only takes 3 arguments
    Code:
    Battle::ItemEffects::OnSwitchIn.add(:CALTROPS,
      proc { |item, battler, battle|
        next if battler.pbOpposingSide.effects[PBEffects::Spikes] >= 3
        battler.pbOpposingSide.effects[PBEffects::Spikes] += 1
        battle.pbDisplay(_INTL("{1} scatters {2} all around {3}'s feet!",
           battler.pbThis, battler.itemName, battler.pbOpposingTeam(true)))
        battler.pbConsumeItem
      }
    )
     
    Back
    Top