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

Check if a pokemon species is owned

mane

I need more class of English:/
17
Posts
13
Years
  • Hello, I think my question is simple.
    how do a script to check if already captured a pokemon, I need it in a script not in an event.
    As I need it in several parts, because it'll contain another script.
     

    mane

    I need more class of English:/
    17
    Posts
    13
    Years
  • Thanks for answer, It appears that there is a syntax error in the part of the if
    Code:
    class Poke_check
      def initialize(nombrepoke)
        @nombrepoke=nombrepoke
      end
      def check
        if $Trainer.owned[PBSpecies::@nombrepoke]
          Kernel.pbMessage(_INTL("text"))
        else
          Kernel.pbMessage(_INTL("another text"))
        end
      end
    end
     
    296
    Posts
    9
    Years
  • Thanks for answer, It appears that there is a syntax error in the part of the if
    Code:
    class Poke_check
      def initialize(nombrepoke)
        @nombrepoke=nombrepoke
      end
      def check
        if $Trainer.owned[PBSpecies::@nombrepoke]
          Kernel.pbMessage(_INTL("text"))
        else
          Kernel.pbMessage(_INTL("another text"))
        end
      end
    end
    You don't need to create a class, but you can make a simple function (def). The error is due to the fact that you have to use the name of a Pokemon in species format, not in string format.

    Code:
    def pokeCheck(species)
      if $Trainer.owned[PBSpecies::species]
          return true
        else
          return false
      end
    end
    To use this, do as follow:
    x-E0
     
    824
    Posts
    8
    Years
  • Code:
    def pokeCheck(species)
      if species.is_a?(String) || species.is_a?(Symbol)
        species=getConst(PBSpecies,species)
      end
      if $Trainer.owned[species]
          return true
        else
          return false
      end
    end

    "Species" is not a constant in the PBSpecies class.
     
    296
    Posts
    9
    Years
  • Code:
    def pokeCheck(species)
      if species.is_a?(String) || species.is_a?(Symbol)
        species=getConst(PBSpecies,species)
      end
      if $Trainer.owned[species]
          return true
        else
          return false
      end
    end

    "Species" is not a constant in the PBSpecies class.
    Oops. My fault. Thank you for your correction.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    You really don't need to use anything other than what Luka told you:

    Code:
    if $Trainer.owned[PBSpecies::Your_Pokemon]
    Some examples of usage:

    Code:
    if $Trainer.owned[PBSpecies::PIKACHU]
    if $Trainer.owned[PBSpecies::MEW]
    if $Trainer.owned[PBSpecies::DARKRAI]
    Note the two colons.
     

    mane

    I need more class of English:/
    17
    Posts
    13
    Years
  • You really don't need to use anything other than what Luka told you:


    Some examples of usage:

    Code:
    if $Trainer.owned[PBSpecies::PIKACHU]
    if $Trainer.owned[PBSpecies::MEW]
    if $Trainer.owned[PBSpecies::DARKRAI]
    Note the two colons.

    Yes, but I get the same error, I don't know if I called it right or not.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    Yes, but I get the same error, I don't know if I called it right or not.
    I don't know if you're calling it right or not either. The trick is to tell us what you're trying to do, and show us what you're actually doing.
     

    mane

    I need more class of English:/
    17
    Posts
    13
    Years
  • As I put at the beginning I try to make a system to check if certain conditions are met and if you have some pokemon in your team can appear an object or pokemon.
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • As I put at the beginning I try to make a system to check if certain conditions are met and if you have some pokemon in your team can appear an object or pokemon.

    You need to brush up on your knowledge of how to use Symbols then.

    This is the proper way to use them:
    Code:
    if $Trainer.owned[PBSpecies::DARKRAI]
    This isn't:
    Code:
    if $Trainer.owned[PBSpecies::@nombrepoke]

    Or if this is proving too difficult, you can just use the species number (i.e. 25) instead of the species symbol (i.e. :PIKACHU).
    Spoiler:
     

    mane

    I need more class of English:/
    17
    Posts
    13
    Years
  • Yes! you're right, thanks it works now but if don't have the pokemon the condition remains true.
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • Yes! you're right, thanks it works now but if don't have the pokemon the condition remains true.
    check if already captured a pokemon
    This is what you asked for. $Trainer.owned does exactly that. It checks if you captured a Pokemon (at least once), and keeps the record of that just like you'd see in the Pokedex. It doesn't keep track of whether or not you are still in possession of the Pokemon. It keeps track of whether or not you have once captured (i.e. been in the possession) of the Pokemon. If you're debugging to fill your boxes, you'll have all the Pokemon as "owned".
     
    Back
    Top