• 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.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • 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

  • 217
    Posts
    15
    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
    }
     
    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
     
    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:
    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.
     
    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