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

[Scripting Question] Check is a valid Pokémon species

  • 752
    Posts
    14
    Years
    • UK
    • Seen Dec 29, 2024
    So for some debug testing I'm setting up wild battles from user input, but the game crashes if The Pokemon species isn't valid, what's the best way to check if its valid before progressing

    Code:
    $game_variables[108] = Kernel.pbMessageFreeText(_INTL("Please enter a pokemon."), _INTL("{1}", $game_variables[108]),false,256,Graphics.width)
        $game_variables[108] = $game_variables[108].upcase
       pbWildBattle($game_variables[108],5)
     
    I used a similar function in my game.

    Spoiler:

    Then you have to call the pbWildBattle function on the result, if the result isn't 0 (it will be 0 in case of cancellation).
     
    turns out there's an easier built in way of doing it I found from the compiler scripts.

    Code:
    $game_variables[108] = Kernel.pbMessageFreeText(_INTL("Please enter a pokemon."), _INTL("{1}", $game_variables[108]),false,256,Graphics.width)
    spec = GameData::Species.try_get($game_variables[108])
    if(spec)
        # Does exist
    else 
        # Doesn't exist
    end
     
    Back
    Top