• 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!
  • 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] Creating a new utility

Telemetius

Tele*
  • 256
    Posts
    10
    Years
    Hi forum

    I just noticed that the utility pbHasType only works for your party.
    So I tried writing a similar one that checks if the opponent has a particular type.
    It's not working and I'd like to know why is that.

    Is it because @battle.opponent.party is not a method?

    Code:
    def pbOppHasType?(type)
      if type.is_a?(String) || type.is_a?(Symbol)
        type=getID(PBTypes,type)
      end
      for pokemon in @battle.opponent.party
        next if pokemon.isEgg?
        return true if pokemon.hasType?(type)
      end
      return false
    end
     
    Hi forum

    I just noticed that the utility pbHasType only works for your party.
    So I tried writing a similar one that checks if the opponent has a particular type.
    It's not working and I'd like to know why is that.

    Is it because @battle.opponent.party is not a method?

    Code:
    def pbOppHasType?(type)
      if type.is_a?(String) || type.is_a?(Symbol)
        type=getID(PBTypes,type)
      end
      for pokemon in @battle.opponent.party
        next if pokemon.isEgg?
        return true if pokemon.hasType?(type)
      end
      return false
    end


    wouldn't be "trainer[0]" instead of "@battle.opponent.party" ?
     
    wouldn't be "trainer[0]" instead of "@battle.opponent.party" ?

    Undefined local variable when using "trainer".
    Is there anything else that might work?
     
    You should read Lesson 2 here:
    (broken link removed)

    This is the danger of just plugging in words, they're most likely not defined.
    Assuming you want to check the trainer outside of a battle, you'll have to instantiate that trainer yourself and then check.

    Try
    Code:
    def pbOppHasType?(type, trainerid, trainername, partyid=0)
      if type.is_a?(String) || type.is_a?(Symbol)
        type=getID(PBTypes,type)
      end
      opp = pbLoadTrainer(trainerid,trainername,partyid=0)
      return false if opp.nil?
      for pokemon in opp[2]
        next if pokemon.isEgg?
        return true if pokemon.hasType?(type)
      end
      return false
    end
     
    An array saves the day.
     
    Back
    Top