• 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!
  • Our weekly protagonist poll is now up! Vote for your favorite Trading Card Game 2 protagonist in the poll by clicking here.
  • 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
    5
    Years
    • Seen Sep 20, 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!
     
    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