• 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] Custom Script keeps trying to find "length"

  • 155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    So Rot8er_ConeX helped me create a script that forces you to encounter a specific Pokemon with in an event. It works well except for one problem. Once the battle ends, the game crashes with this error:
    Spoiler:
    For some strange reason, it's looking for "length" in the code, but the code itself never even calls for "length" in the first place, so I don't understand why it's even looking for it. Here's the code for the method:
    Code:
    def pbSpecificWildBattle(pokemon,level,variable=nil,canescape=true,canlose=false)
      if (Input.press?(Input::CTRL) && $DEBUG) || $Trainer.pokemonCount==0
        if $Trainer.pokemonCount>0
          Kernel.pbMessage(_INTL("SKIPPING BATTLE..."))
        end
        pbSet(variable,1)
        $PokemonGlobal.nextBattleBGM=nil
        $PokemonGlobal.nextBattleME=nil
        $PokemonGlobal.nextBattleBack=nil
        return true
      end
      handled=[nil]
      Events.onWildBattleOverride.trigger(nil,pokemon.species,level,handled)
      if handled[0]!=nil
        return handled[0]
      end
      currentlevels=[]
      for i in $Trainer.party
        currentlevels.push(i.level)
      end
      scene=pbNewBattleScene
      battle=PokeBattle_Battle.new(scene,$Trainer.party,[pokemon],$Trainer,nil)
      battle.internalbattle=true
      battle.cantescape=!canescape
      pbPrepareBattle(battle)
      decision=0
      pbBattleAnimation(pbGetWildBattleBGM(pokemon.species)) { 
         pbSceneStandby {
            decision=battle.pbStartBattle(canlose)
         }
         for i in $Trainer.party; (i.makeUnmega rescue nil); end
         if $PokemonGlobal.partner
           pbHealAll
           for i in $PokemonGlobal.partner[3]
             i.heal
             i.makeUnmega rescue nil
           end
         end
         if decision==2 || decision==5 # if loss or draw
           if canlose
             for i in $Trainer.party; i.heal; end
             for i in 0...10
               Graphics.update
             end
    #       else
    #         $game_system.bgm_unpause
    #         $game_system.bgs_unpause
    #         Kernel.pbStartOver
           end
         end
         Events.onEndBattle.trigger(nil,decision,canlose)
      }
      Input.update
      pbSet(variable,decision)
      Events.onWildBattleEnd.trigger(nil,species,level,decision)
      return (decision!=2)
    end
    And here's the code used in the event script:
    Code:
    poke=pbGenerateWildPokemon(PBSpecies::KROOKODILE,35)
    poke.makeDelta
    poke.deltatype=getConst(PBTypes,:WATER)
    poke.deltatype2=getConst(PBTypes,:POISON)
    pbSpecificWildBattle(poke,0)
    What am I doing wrong? This is very frustrating as I have no idea why it's searching for "length".
     
    Last edited by a moderator:
  • 296
    Posts
    9
    Years
    Your report says all you need: "Section 129:70". It means that in the 129th script, starting from top to bottom, in the 70th line, there is a conflict with your code. What's in that script? Post a reply with code or spoiler tag, containing this section (e.g. PokeBattle_Scene), so i can help you.
     
  • 155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    Your report says all you need: "Section 129:70". It means that in the 129th script, starting from top to bottom, in the 70th line, there is a conflict with your code. What's in that script? Post a reply with code or spoiler tag, containing this section (e.g. PokeBattle_Scene), so i can help you.
    I think I miscounted. When I counted the scripts, I came across this:
    Spoiler:
    And this doesn't seem right.
    This is in PField_Field by the way.
     
    Last edited:
  • 296
    Posts
    9
    Years
    Yes, you probably miscounted. You must also take into account the "blank" script and those that have no name.
    E.g., in the newest version of Essentials (16.2), the 129th script section is "Pokemon_Sprites".
     
  • 155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    Yes, you probably miscounted. You must also take into account the "blank" script and those that have no name.
    E.g., in the newest version of Essentials (16.2), the 129th script section is "Pokemon_Sprites".
    OH! Now I know what you mean! Sorry about that.
    The 129th section in my file is Pokemon_ShadowPokemon. When going through line 70, I find this:
    Code:
    Events.onEndBattle+=proc {|sender,e|
       decision=e[0]
       canlose=e[1]
       for i in 0...$PokemonTemp.heartgauges.[COLOR=Red][B]length[/B][/COLOR]
         pokemon=$Trainer.party[i]
         if pokemon && ($PokemonTemp.heartgauges[i] &&
            $PokemonTemp.heartgauges[i]!=0 && pokemon.heartgauge==0)
           pbReadyToPurify(pokemon)
         end
       end
    }
     
    Last edited:
  • 296
    Posts
    9
    Years
    OH! Now I know what you mean! Sorry about that.
    The 129th section in my file is Pokemon_ShadowPokemon. When going through line 70, I find this:
    Code:
    Events.onEndBattle+=proc {|sender,e|
       decision=e[0]
       canlose=e[1]
       for i in 0...$PokemonTemp.heartgauges.[COLOR=Red][B]length[/B][/COLOR]
         pokemon=$Trainer.party[i]
         if pokemon && ($PokemonTemp.heartgauges[i] &&
            $PokemonTemp.heartgauges[i]!=0 && pokemon.heartgauge==0)
           pbReadyToPurify(pokemon)
         end
       end
    }
    This is the correct code:
    Code:
    def pbSpecificWildBattle(pokemon,level,variable=nil,canescape=true,canlose=false)
      if (Input.press?(Input::CTRL) && $DEBUG) || $Trainer.pokemonCount==0
        if $Trainer.pokemonCount>0
          Kernel.pbMessage(_INTL("SKIPPING BATTLE..."))
        end
        pbSet(variable,1)
        $PokemonGlobal.nextBattleBGM=nil
        $PokemonGlobal.nextBattleME=nil
        $PokemonGlobal.nextBattleBack=nil
        return true
      end
      handled=[nil]
      species=pokemon.species
      Events.onWildBattleOverride.trigger(nil,species,level,handled)
      if handled[0]!=nil
        return handled[0]
      end
      currentlevels=[]
      for i in $Trainer.party
        currentlevels.push(i.level)
      end
      Events.onStartBattle.trigger(nil,pokemon)
      scene=pbNewBattleScene
      battle=PokeBattle_Battle.new(scene,$Trainer.party,[pokemon],$Trainer,nil)
      battle.internalbattle=true
      battle.cantescape=!canescape
      pbPrepareBattle(battle)
      decision=0
      pbBattleAnimation(pbGetWildBattleBGM(species)) { 
         pbSceneStandby {
            decision=battle.pbStartBattle(canlose)
         }
         for i in $Trainer.party; (i.makeUnmega rescue nil); end
         if $PokemonGlobal.partner
           pbHealAll
           for i in $PokemonGlobal.partner[3]
             i.heal
             i.makeUnmega rescue nil
           end
         end
         if decision==2 || decision==5 # if loss or draw
           if canlose
             for i in $Trainer.party; i.heal; end
             for i in 0...10
               Graphics.update
             end
    #       else
    #         $game_system.bgm_unpause
    #         $game_system.bgs_unpause
    #         Kernel.pbStartOver
           end
         end
         Events.onEndBattle.trigger(nil,decision,canlose)
      }
      Input.update
      pbSet(variable,decision)
      Events.onWildBattleEnd.trigger(nil,species,level,decision)
      return (decision!=2)
    end
     
  • 155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    Oh, one more thing, actually. I'm trying to connect the script to events since when I tried it out before, fleeing, catching, or defeating the Pokemon didn't trigger the events like a normal fateful encounter would, but whenever I tried to connect them, fleeing always results in the event thinking you beat them.
    Code:
    poke=pbGenerateWildPokemon(PBSpecies::KROOKODILE,35)
    poke.makeDelta
    poke.deltatype=getConst(PBTypes,:WATER)
    poke.deltatype2=getConst(PBTypes,:POISON)
    result = pbSpecificWildBattle(poke,0)
    pbSet(1, result == BR_WIN ? 0 : 1)
    I have the Temp Pokemon Choice programmed to where it's 1 if you win, 3 if you flee, and 4 if you catch it, but fleeing seems to trigger 1.
     
  • 129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    I don't know how your pbSpecificWildBattle function works, but the Essentials default pbWildBattle function has the following at the end:

    Code:
      return (decision!=2)
    That will return a true from the method if you've not lost (which includes fleeing and catching), and false if you have lost. If this is at the end of pbSpecificWildBattle, then you're losing information there in a similar fashion.

    Further, that snippet of code you have there is deliberately setting global variable 1 to either 0 or 1, 0 if you win, 1 if you didn't (assuming BR_WIN is defined as either true or 1).

    Of course, pbWildBattle in Essentials has an optional parameter where you can pass a variable number, and it'll store the battle decision in that global variable itself. You should see if pbSpecificWildBattle has something similar and use that.

    Code:
    def pbWildBattle(species,level,variable=nil,canescape=true,canlose=false)
     
  • 155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    I don't know how your pbSpecificWildBattle function works, but the Essentials default pbWildBattle function has the following at the end:

    Code:
      return (decision!=2)
    That will return a true from the method if you've not lost (which includes fleeing and catching), and false if you have lost. If this is at the end of pbSpecificWildBattle, then you're losing information there in a similar fashion.

    Further, that snippet of code you have there is deliberately setting global variable 1 to either 0 or 1, 0 if you win, 1 if you didn't (assuming BR_WIN is defined as either true or 1).

    Of course, pbWildBattle in Essentials has an optional parameter where you can pass a variable number, and it'll store the battle decision in that global variable itself. You should see if pbSpecificWildBattle has something similar and use that.

    Code:
    def pbWildBattle(species,level,variable=nil,canescape=true,canlose=false)
    It does, actually. However, I'm not exactly sure how to actually call each decision. I tried replacing BR_WIN with "result == @decision", but that just makes it to where it thinks every action is when you run from it in battle.
     
  • 296
    Posts
    9
    Years
    Oh, one more thing, actually. I'm trying to connect the script to events since when I tried it out before, fleeing, catching, or defeating the Pokemon didn't trigger the events like a normal fateful encounter would, but whenever I tried to connect them, fleeing always results in the event thinking you beat them.
    Code:
    poke=pbGenerateWildPokemon(PBSpecies::KROOKODILE,35)
    poke.makeDelta
    poke.deltatype=getConst(PBTypes,:WATER)
    poke.deltatype2=getConst(PBTypes,:POISON)
    result = pbSpecificWildBattle(poke,0)
    pbSet(1, result == BR_WIN ? 0 : 1)
    I have the Temp Pokemon Choice programmed to where it's 1 if you win, 3 if you flee, and 4 if you catch it, but fleeing seems to trigger 1.
    It seems pretty clear why the result is always 1:
    Code:
    pbSet(1, result == BR_WIN ? 0 : 1)
    With your code, the Global variable is set to 1, because the game checks if result is equal to BR_WIN; in that case the value is 1, while in the other case is 0.
    Your code should to be like this:
    Code:
    poke=pbGenerateWildPokemon(PBSpecies::KROOKODILE,35)
    poke.makeDelta
    poke.deltatype=getConst(PBTypes,:WATER)
    poke.deltatype2=getConst(PBTypes,:POISON)
    pbSet(1,pbSpecificWildBattle(poke,0))
     
  • 155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    Your code should to be like this:
    Code:
    poke=pbGenerateWildPokemon(PBSpecies::KROOKODILE,35)
    poke.makeDelta
    poke.deltatype=getConst(PBTypes,:WATER)
    poke.deltatype2=getConst(PBTypes,:POISON)
    pbSet(1,pbSpecificWildBattle(poke,0))
    Sadly, that didn't work either. Making the Krookodile faint or catching it just treated it as though I ran from it.
     
  • 296
    Posts
    9
    Years
    Make a test: before this line
    Code:
    pbSet(variable,decision)

    Make a new one:
    Code:
    Kernel.pbMessage(_INTL("{1}",decision))
     
  • 155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    Make a test: before this line
    Code:
    pbSet(variable,decision)
    Make a new one:
    Code:
    Kernel.pbMessage(_INTL("{1}",decision))
    Running away has returned the message "3".
    Making it faint has returned the message "1", but the defeated event didn't play.
    Catching it has returned the massage "4", but it still remains on the map.

    So now I know that it's calling the decisions properly, but it's not calling the events for whatever reason.
     
  • 296
    Posts
    9
    Years
    I'll make a test for you and then i'll post the solution.

    Try to do this:
    Code:
    poke=pbGenerateWildPokemon(PBSpecies::KROOKODILE,35)
    poke.makeDelta
    poke.deltatype=getConst(PBTypes,:WATER)
    poke.deltatype2=getConst(PBTypes,:POISON)
    pbSpecificWildBattle(poke,0,1)
     
    Last edited by a moderator:
  • 155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    Custom Script keeps trying to find "length"

    If it helps any, this is how the event is set up.
     
  • 155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    Try to do this:
    Code:
    poke=pbGenerateWildPokemon(PBSpecies::KROOKODILE,35)
    poke.makeDelta
    poke.deltatype=getConst(PBTypes,:WATER)
    poke.deltatype2=getConst(PBTypes,:POISON)
    pbSpecificWildBattle(poke,0,1)
    That seemed to fix it! Thank-you!
     
    Back
    Top