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

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

772
Posts
13
Years
    • UK
    • Seen May 7, 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)
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    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).
     
    772
    Posts
    13
    Years
    • UK
    • Seen May 7, 2024
    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