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

Checking the team for a certain type

Franzo

Developing something...
95
Posts
16
Years
  • Like the pbHasSpecies?(:BULBASAUR), I wanted to make a function that checks the team for a certain type.

    I added this in PokemonUtilities:

    def pbHasType?(types) # Searches team for certain type
    if types.is_a?(String)
    types=getID(PBTypes,types)
    end
    for pokemon in $Trainer.party
    next if pokemon.egg?
    return true if pokemon.getID(PBTypes,types)==types
    end
    return false
    end

    I made a test event. it's page has this in it:

    Conditional Branch: Script: pbHasType?(:BUG)
    Text: BUG type in team.

    else

    Text: No BUG type in team.

    Branch End

    But whatever pokémon I have in the party, it always says "No BUG type in team." I'm pretty sure the Utitlities code is incorrect but i'm not very experienced with Ruby. Any help?
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    The line where you check the type of each Pokémon in the party is definitely incorrect. Use this:

    Code:
    def pbHasTypeInParty?(type)
      if type.is_a?(String) || type.is_a?(Symbol)
        return false if !hasConst?(PBTypes,type)
        type=getID(PBTypes,type)
      end
      for pokemon in $Trainer.party
        next if pokemon.egg?
        return true if pokemon.hasType?(type)
      end
      return false
    end
    The method name is different and more descriptive. There's also a check to make sure you're looking for a type that exists - without this check, any non-existent type would be treated as type 0 (Normal). It's there for completeness.
     
    Back
    Top