• 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] [V18.1] Syntax Error on Item Effect

  • 34
    Posts
    4
    Years
    • Seen May 31, 2024
    Hey peeps,

    I'm creating an item that turns on a switch when you use it, and off when you use it again. It functions fine! Until I add in the pbMessage function. Currently the script looks like this:

    Code:
    ItemHandlers::UseInField.add(:ULTRAMAXREPEL,proc { |item|
    if $game_switches[225]==true
       $game_switches[225] = false
       pbMessage(_INTL("The powerful Repel dissapates... Wild Pokemon have returned!"))
      next 1
    end
    if $game_switches[225]==false
       $game_switches[225] = true  
       pbMessage(_INTL("The powerful Repel wafts around... Wild Pokemon have fled!")
      next 1
     end
    })

    And it is without fail the second pbMessage that throws up an error. If I remove that one, it functions fine. Does anyone have the expertise to point out the fault here? I'm tearing my hair out!
    Cheers in advance!
     
  • 311
    Posts
    4
    Years
    You're missing a ')' in the pbMessage bit.

    However, you can also optimize your code a bit, and make it easier to read.
    Code:
    ItemHandlers::UseInField.add(:ULTRAMAXREPEL,proc { |item|
        $game_switches[225] = !$game_switches[225]
        if $game_switches[225] == true
          pbMessage(_INTL("The powerful Repel dissapates... Wild Pokemon have returned!"))
        else
          pbMessage(_INTL("The powerful Repel wafts around... Wild Pokemon have fled!"))
        end
        next 1
    })

    You can just set your switch to the opposite value of the switch. Looks a bit nicer.

    The code can actually be cleaned up further:
    Spoiler:
     
    Back
    Top