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

Error using pbAddPokemon and a related custom script

7
Posts
8
Years
    • Seen Nov 19, 2020
    I'm using an essentials script made by umbreon and modified by me to randomize the pokemon roughly around the same strength

    It seems to randomize trainers and triggered battles just fine but I crash with an error when using pbAddPokemon, the original unmodified script crashes as well though with a different error (something along the lines of pokemon 721 being invalid)

    edit: it crashes even with the switch turned off, so that inner loop isn't even touched and it still crashes. Just confused as too why

    Code:

    Code:
    module RandomizedChallenge
      Switch = 36 # switch ID to randomize a pokemon, if it's on then ALL
                  # pokemon will be randomized. No exceptions.
                  #
      Range = 0.05 # Percentage of difference between the stats use 0.05 format
    end
    
    ######################### End of settings, edit below at your own risk
    class PokeBattle_Pokemon
      
      alias randomized_init initialize
      def initialize(species,level,player=nil,withMoves=true)
        statTotal = getBaseStatTotal(species)
        if $game_switches && $game_switches[RandomizedChallenge::Switch]
          generatedMon = rand(PBSpecies.maxValue - 1) + 1
          randTotal = getBaseStatTotal(generatedMon)
          while (randTotal+225) <= (statTotal+225)*(1-RandomizedChallenge::Range) || (randTotal+225) >= (statTotal+225)*(1+RandomizedChallenge::Range)
              generatedMon = rand(PBSpecies.maxValue - 1) + 1
              randTotal = getBaseStatTotal(generatedMon)
              if randTotal == 236
                randTotal *= 2; 
              end
            end 
    
        randomized_init(generatedMon, level, player, withMoves)
        end
      end
    end
    
    def getBaseStatTotal(species)
      dexdata=pbOpenDexData
      pbDexDataOffset(dexdata,species,10)
      bs=[
        dexdata.fgetb, # HP
        dexdata.fgetb, # Attack
        dexdata.fgetb, # Defense
        dexdata.fgetb, # Speed
        dexdata.fgetb, # Special Attack
        dexdata.fgetb  # Special Defense
      ]
      dexdata.close
      return bs.inject{|sum,x| sum + x }
    end

    Here's the error

    Code:
    ---------------------------
    Pokemon Essentials Gen 6
    ---------------------------
    Exception: RuntimeError
    
    Message: Script error within event 2, map 33 (Canvas Town):
    
    Exception: TypeError
    
    Message: Section041:559:in `[]'no implicit conversion from nil to integer
    
    ***Full script:
    
    pbAddPokemon(:PIKACHU,20)
    
    
    Interpreter:243:in `pbExecuteScript'
    
    Intl_Messages:559:in `get'
    
    Intl_Messages:669:in `get'
    
    Intl_Messages:706:in `pbGetMessage'
    
    PBSpecies:724:in `getName'
    
    PSystem_Utilities:1742:in `pbAddPokemon'
    
    (eval):1:in `pbExecuteScript'
    
    Interpreter:1606:in `eval'
    
    Interpreter:243:in `pbExecuteScript'
    
    Interpreter:1606:in `command_355'
    
    
    
    Interpreter:276:in `pbExecuteScript'
    
    Interpreter:1606:in `command_355'
    
    Interpreter:494:in `execute_command'
    
    Interpreter:193:in `update'
    
    Interpreter:106:in `loop'
    
    Interpreter:198:in `update'
    
    Scene_Map:103:in `update'
    
    Scene_Map:101:in `loop'
    
    Scene_Map:114:in `update'
    
    Scene_Map:68:in `main'
    
    
    
    This exception was logged in 
    
    C:\Users\Krig\Saved Games/Pokemon Essentials Gen 6/errorlog.txt.
    
    Press Ctrl+C to copy this message to the clipboard.
    ---------------------------
    OK   
    ---------------------------


    Edit: Thanks to whoever changed the title, original may have been a little vague
     
    Last edited:

    Pookachurin

    Pooka The Pikachu
    18
    Posts
    8
    Years
  • The error doesn't seem to be in the script you provided. According to the error code, the error is located in "Canvas Town" in Event 2's code.
    You can find Event 2 by looking at your events for the number 2:
    Error using pbAddPokemon and a related custom script

    Once you find Event 2, please reply with a screenshot of Event 2's code so I can look at it.
    -Pooka
     
    7
    Posts
    8
    Years
    • Seen Nov 19, 2020
    Sorry for not being more clear, the event was just a plain add pokemon script. I figured out the issue I was passing generatedMon, but if the switch was off then generatedMon was never generated so I was passing nothing.
     
    Back
    Top