• 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] Syntax Error Somewhere

220
Posts
13
Years
    • Seen Nov 29, 2021
    So I keep getting a syntax error pointing to the last line of this code (the "}"), and I can't figure out why:
    Code:
    Events.onStepTakenTransferPossible+=proc {|sender,e|
      handled=e[0]
      next if handled[0]
      if $PokemonGlobal.stepcount % 4 == 0
        for i in $Trainer.party
          if isConst?(pokemon.ability,PBAbilities,:PICKUP) && 
          !pokemon.isEgg? && pokemon.item==0 && rand(10)==0
          pickupList=pbDynamicItemList(
             :POTION,
             :ANTIDOTE,
             :SUPERPOTION,
             :GREATBALL,
             :REPEL,
             :ESCAPEROPE,
             :FULLHEAL,
             :HYPERPOTION,
             :ULTRABALL,
             :REVIVE,
             :RARECANDY,
             :SUNSTONE,
             :MOONSTONE,
             :HEARTSCALE,
             :FULLRESTORE,
             :MAXREVIVE,
             :PPUP,
             :MAXELIXIR
          )
          pickupListRare=pbDynamicItemList(
             :HYPERPOTION,
             :NUGGET,
             :KINGSROCK,
             :FULLRESTORE,
             :ETHER,
             :IRONBALL,
             :DESTINYKNOT,
             :ELIXIR,
             :DESTINYKNOT,
             :LEFTOVERS,
             :DESTINYKNOT
          )
          return if pickupList.length!=18
          return if pickupListRare.length!=11
          randlist=[30,10,10,10,10,10,10,4,4,1,1]
          items=[]
          plevel=[100,pokemon.level].min
          itemstart=(plevel-1)/10
          itemstart=0 if itemstart<0
          for i in 0...9
            items.push(pickupList[itemstart+i])
          end
          items.push(pickupListRare[itemstart])
          items.push(pickupListRare[itemstart+1])
          rnd=rand(100)
          cumnumber=0
          for i in 0...11
            cumnumber+=randlist[i]
            if rnd<cumnumber
              pokemon.setItem(items[i])
              break
            end
          end
        end
      end
    }
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • You're missing an end there buddy. That's why careful code indentation is important. You never ended off your
    Code:
    if isConst?(pokemon.ability,PBAbilities,:PICKUP) && 
    !pokemon.isEgg? && pokemon.item==0 && rand(10)==0
     
    220
    Posts
    13
    Years
    • Seen Nov 29, 2021
    Thanks!
    Next problem is it crashes when called :/
    Undefined local method or variable "Pokemon"

    EDIT: And fixed! Switched the first "i" to "Pokemon".

    Now I have Pickup give you a item 1% of the time every 4 steps:
    Code:
    Events.onStepTakenTransferPossible+=proc {|sender,e|
      handled=e[0]
      next if handled[0]
      if $PokemonGlobal.stepcount % 4 == 0
        for pokemon in $Trainer.party
          if isConst?(pokemon.ability,PBAbilities,:PICKUP) && 
          !pokemon.isEgg? && pokemon.item==0 && rand(100)==0
            pickupList=pbDynamicItemList(
               :POTION,
               :ANTIDOTE,
               :SUPERPOTION,
               :GREATBALL,
               :REPEL,
               :ESCAPEROPE,
               :FULLHEAL,
               :HYPERPOTION,
               :ULTRABALL,
               :REVIVE,
               :RARECANDY,
               :SUNSTONE,
               :MOONSTONE,
               :HEARTSCALE,
               :FULLRESTORE,
               :MAXREVIVE,
               :PPUP,
               :MAXELIXIR
            )
            pickupListRare=pbDynamicItemList(
               :HYPERPOTION,
               :NUGGET,
               :KINGSROCK,
               :FULLRESTORE,
               :ETHER,
               :IRONBALL,
               :DESTINYKNOT,
               :ELIXIR,
               :DESTINYKNOT,
               :LEFTOVERS,
               :DESTINYKNOT
            )
            return if pickupList.length!=18
            return if pickupListRare.length!=11
            randlist=[30,10,10,10,10,10,10,4,4,1,1]
            items=[]
            plevel=[100,pokemon.level].min
            itemstart=(plevel-1)/10
            itemstart=0 if itemstart<0
            for i in 0...9
              items.push(pickupList[itemstart+i])
            end
            items.push(pickupListRare[itemstart])
            items.push(pickupListRare[itemstart+1])
            rnd=rand(100)
            cumnumber=0
            for i in 0...11
              cumnumber+=randlist[i]
              if rnd<cumnumber
                pokemon.setItem(items[i])
                break
              end
            end
          end
        end
      end
    }
     
    Last edited:
    971
    Posts
    7
    Years
    • Age 21
    • Seen Nov 28, 2022
    Thanks!
    Next problem is it crashes when called :/

    Syntax errors are the worst errors in Ruby in my opinion. If you're editing massive scripts and overlook one syntax error, you're done for. I've had this more than once, unfortunately. And as Luka said, code indentation is crucial.
     
    220
    Posts
    13
    Years
    • Seen Nov 29, 2021
    Syntax errors are the worst errors in Ruby in my opinion. If you're editing massive scripts and overlook one syntax error, you're done for. I've had this more than once, unfortunately. And as Luka said, code indentation is crucial.

    Ah I solved it, see above.
    Thankfully the only syntax error was the one Luka pointed out. The other was me just using i for each party member and then not referencing them by i.
     
    Back
    Top