• 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] HELP ME FIX THIS CODE!!! :(

  • 163
    Posts
    5
    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!!! :(
     

    DarrylBD99

    Content Creator and Game Developer
  • 321
    Posts
    4
    Years
    From the way I see it, I am pretty sure you didn't define anything into the variable "newspecies". Can you show us the syntax error message?
     
  • 23,771
    Posts
    11
    Years
    • She/Her, It/Its
    • Seen today
    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.
     
  • 163
    Posts
    5
    Years
    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"?
     
  • 163
    Posts
    5
    Years
    Did some modification to the code but I need someone to check if it's correct!
    Spoiler:
     

    Luka S.J.

    Jealous Croatian
  • 1,270
    Posts
    15
    Years
    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:
  • 163
    Posts
    5
    Years
    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! :(
     
  • 71
    Posts
    6
    Years
    • Seen May 24, 2024
    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
     
  • 163
    Posts
    5
    Years
    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.
     
  • 163
    Posts
    5
    Years
    Now this came up instead of evolving the Pokemon!
    Spoiler:


    What does it mean?
     
  • 163
    Posts
    5
    Years
    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?! :(
     
  • 286
    Posts
    5
    Years
    • Seen Jun 4, 2024
    [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.
     
  • 163
    Posts
    5
    Years
    Okay! Here's the code I used:
    Spoiler:
     
  • 1,409
    Posts
    10
    Years
    • Seen today
    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.
     
  • 163
    Posts
    5
    Years
    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?
     
  • 163
    Posts
    5
    Years
    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