• 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!
  • Serena, Kris, Dawn, Red - which Pokémon protagonist is your favorite? Let us know by voting in our grand final favorite protagonist poll!
  • PokéCommunity supports the Stop Killing Games movement. If you're a resident of the UK or EU, consider signing one of the petitions to stop publishers from destroying games. Click here for more information!
  • 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
    6
    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