• 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.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • 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

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