• 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!
  • Dawn, Gloria, Juliana, or Summer - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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] $game_switches not actually flipping a switch

  • 16
    Posts
    13
    Years
    • Seen Dec 13, 2016
    In this script I want to give the player a key item that allows him to change back and forth from the costume to the default whenever it gets used. However, when I try to toggle a switch by using $game_switches to accomplish this, nothing happens to the switch.

    Here's my code:

    Spoiler:


    the variable is the player's gender, and the switch controls if the new outfit is on or not.

    By all means, I think that it should be working properly, but I don't know why its not. I'm on essentials 16.2
     
    If you just need to change outfit use: "$Trainer.outfit=XX" instead of pbChangePlayer.
     
    Code:
    ==
    is testing for equality, not setting. You want a singular '='
    Similarly,
    Code:
    !$game_switches[62]
    isn't setting anything, it's just returning the opposite value of the switch's value. If you want to toggle a switch, say
    Code:
    $game_switches[62] = !$game_switches[62]
     
    Code:
    ==
    is testing for equality, not setting. You want a singular '='
    Similarly,
    Code:
    !$game_switches[62]
    isn't setting anything, it's just returning the opposite value of the switch's value. If you want to toggle a switch, say
    Code:
    $game_switches[62] = !$game_switches[62]

    I was unaware that was how the $game_switches line worked. I used this to get it to work. Here's the working code: (switch 62 is to check if the new costume is on and switch 63 checks gender.)

    Code:
    def pbPoliceUniform
    if !$game_switches[62]
    pbChangePlayer(2)
    $game_switches[62] = !$game_switches[62]
    return 1
    end
    if !$game_switches[63] and $game_switches[62]
    pbChangePlayer(1)
    $game_switches[62] = !$game_switches[62]
    return 2
    end
    if $game_switches[63] and $game_switches[62]
    pbChangePlayer(0)
    $game_switches[62] = !$game_switches[62]
    return 2
    end
    end
    
    ItemHandlers::UseFromBag.add(:POLICEUNIFORM,proc{|item| pbPoliceUniform 
    })
     
    Back
    Top