• 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.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • 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] HELP ME FIX THIS CODE!!! :(

  • 158
    Posts
    6
    Years
    Okay so I am working on the code that makes the Reveal Glass also evolve Eldish into Eldragon, but I keep getting Syntax and I don't know what the problem is!

    Here's the modified Reveal Glass code:
    Code:
    ItemHandlers::UseOnPokemon.add(:REVEALGLASS,proc{|item,pokemon,scene|
       if (isConst?(pokemon.species,PBSpecies,:TORNADUS) ||
          isConst?(pokemon.species,PBSpecies,:THUNDURUS) ||
          isConst?(pokemon.species,PBSpecies,:LANDORUS))
         if pokemon.hp>0
           pokemon.form=(pokemon.form==0) ? 1 : 0
           scene.pbRefresh
           scene.pbDisplay(_INTL("{1} changed Forme!",pokemon.name))
           next true
         else
           scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
         end
         elsif (isConst?(pokemon.species,PBSpecies,:ELDISH)
           if pokemon.hp>0
            pbFadeOutInWithMusic(99999){
              evo=PokemonEvolutionScene.new
              evo.pbStartScreen(pokemon,newspecies)
              evo.pbEvolution(false)
              evo.pbEndScreen
              if scene.is_a?(PokemonBag_Scene)
                scene.pbRefreshAnnotations(proc{|p| pbCheckEvolution(p,item)>0 })
                scene.pbRefresh
            end
           next true
        else
         scene.pbDisplay(_INTL("It had no effect."))
         next false
       end
    })

    Please tell me what's wrong!!! :(
     
    Your code looks a little confusing. I assume the "elsif" and the last "else" statement belong to the topmost "if"? They're a little too far to the right.

    If I had to guess I'd say you're missing an "end" somewhere.

    Strangely, I tried adding "end" somewhere but nothing! Also, whaddaya mean the topmost "if"?
     
    Did some modification to the code but I need someone to check if it's correct!
    Spoiler:
     
    Get into the habit of properly indenting your code, and you won't be missing syntax components (response to the opening post):
    Code:
    ItemHandlers::UseOnPokemon.add(:REVEALGLASS,proc{|item,pokemon,scene|
      if (isConst?(pokemon.species,PBSpecies,:TORNADUS) ||
        isConst?(pokemon.species,PBSpecies,:THUNDURUS) ||
        isConst?(pokemon.species,PBSpecies,:LANDORUS))
        if pokemon.hp>0
          pokemon.form=(pokemon.form==0) ? 1 : 0
          scene.pbRefresh
          scene.pbDisplay(_INTL("{1} changed Forme!",pokemon.name))
          next true
        else
          scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
        end
      elsif isConst?(pokemon.species,PBSpecies,:ELDISH)
        if pokemon.hp>0
          pbFadeOutInWithMusic(99999){
            evo=PokemonEvolutionScene.new
            evo.pbStartScreen(pokemon,newspecies)
            evo.pbEvolution(false)
            evo.pbEndScreen
            if scene.is_a?(PokemonBag_Scene)
              scene.pbRefreshAnnotations(proc{|p| pbCheckEvolution(p,item)>0 })
              scene.pbRefresh
            end # <------------------------------------- END MISSING HERE
          } # <----------------------------------------- CURLY BRACKET MISSING HERE
        end
        next true
      else
        scene.pbDisplay(_INTL("It had no effect."))
        next false
      end
    })
     
    Last edited:
    Get into the habit of properly indenting your code, and you won't be missing syntax components (response to the opening post):
    Code:
    ItemHandlers::UseOnPokemon.add(:REVEALGLASS,proc{|item,pokemon,scene|
      if (isConst?(pokemon.species,PBSpecies,:TORNADUS) ||
        isConst?(pokemon.species,PBSpecies,:THUNDURUS) ||
        isConst?(pokemon.species,PBSpecies,:LANDORUS))
        if pokemon.hp>0
          pokemon.form=(pokemon.form==0) ? 1 : 0
          scene.pbRefresh
          scene.pbDisplay(_INTL("{1} changed Forme!",pokemon.name))
          next true
        else
          scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
        end
      elsif (isConst?(pokemon.species,PBSpecies,:ELDISH)
        if pokemon.hp>0
          pbFadeOutInWithMusic(99999){
            evo=PokemonEvolutionScene.new
            evo.pbStartScreen(pokemon,newspecies)
            evo.pbEvolution(false)
            evo.pbEndScreen
            if scene.is_a?(PokemonBag_Scene)
              scene.pbRefreshAnnotations(proc{|p| pbCheckEvolution(p,item)>0 })
              scene.pbRefresh
            end # <------------------------------------- END MISSING HERE
          } # <----------------------------------------- CURLY BRACKET MISSING HERE
        end
        next true
      else
        scene.pbDisplay(_INTL("It had no effect."))
        next false
      end
    })

    I'm still getting Syntax! :(
     
    Code:
         elsif (isConst?(pokemon.species,PBSpecies,:ELDISH)

    the missing ")"
    he spotted it and directed you to the elsif :P just gotta take a close look at it
    i know u probabaly copied this from the 2nd line in that code but notice how in the 4th line the bracket is closed
     
    Code:
         elsif (isConst?(pokemon.species,PBSpecies,:ELDISH)

    the missing ")"
    he spotted it and directed you to the elsif :P just gotta take a close look at it
    i know u probabaly copied this from the 2nd line in that code but notice how in the 4th line the bracket is closed

    Oh.
     
    Now this came up instead of evolving the Pokemon!
    Spoiler:


    What does it mean?
     
    Happened testing evolution method!

    [Pokémon Essentials version 17.2]
    Exception: NameError
    Message: undefined local variable or method `newspecies' for nil:NilClass
    PItem_ItemEffects:902
    PItem_ItemEffects:889:in `call'
    EventHandlers:150:in `trigger'
    PItem_Items:228:in `triggerUseOnPokemon'
    PItem_Items:634:in `pbUseItem'
    PItem_Items:628:in `loop'
    PItem_Items:647:in `pbUseItem'
    PItem_Items:624:in `pbFadeOutIn'
    PItem_Items:624:in `pbUseItem'
    PScreen_Bag:484:in `pbStartScreen'

    What does it mean? What am I doing wrong?! :(
     
    [Pokémon Essentials version 17.2]
    Exception: NameError
    Message: undefined local variable or method `newspecies' for nil:NilClass
    PItem_ItemEffects:902
    PItem_ItemEffects:889:in `call'
    EventHandlers:150:in `trigger'
    PItem_Items:228:in `triggerUseOnPokemon'
    PItem_Items:634:in `pbUseItem'
    PItem_Items:628:in `loop'
    PItem_Items:647:in `pbUseItem'
    PItem_Items:624:in `pbFadeOutIn'
    PItem_Items:624:in `pbUseItem'
    PScreen_Bag:484:in `pbStartScreen'

    What does it mean? What am I doing wrong?! :(

    It means that you are using a variable that doesn't exist, hence "undefined local variable or method". Try reading the error message before you ask for help, because they're often self-explanatory. In this case, look for "newspecies" in the code and find out why it has not yet been defined.
     
    Okay! Here's the code I used:
    Spoiler:
     
    Okay! Here's the code I used:
    Spoiler:

    Well there ya go. You have two instances of "newspecies" (bolded), but you dont have that variable set to anything. "Newspecies" doesn't mean anything on its own. You probably just copied something from elsewhere in the script that uses "newspecies" as a variable for something.
     
    Well there ya go. You have two instances of "newspecies" (bolded), but you dont have that variable set to anything. "Newspecies" doesn't mean anything on its own. You probably just copied something from elsewhere in the script that uses "newspecies" as a variable for something.

    Which one do I change?
     
    Which one do I change?

    Since only Eldish can evolve using the Reveal Glass, you can replace newspecies with getConst(PBSpecies,:EVO) I think. If that doesn't work then try replacing newspecies with the ID of the Eldish Evolution.
     
    Since only Eldish can evolve using the Reveal Glass, you can replace newspecies with getConst(PBSpecies,:EVO) I think. If that doesn't work then try replacing newspecies with the ID of the Eldish Evolution.

    But which newspecies do I replace? The one near if pokemon.hp>0 or the other one?
     
    Back
    Top