• 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] $game_switches not actually flipping a switch

16
Posts
12
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
     

    Sir_Tman

    Overworked game Dev
    201
    Posts
    8
    Years
  • I pretty sure that "and"
    Code:
    if $game_variables[27]==0 and !$game_switches[62]
    Is meant to be "&&"
    Code:
    if $game_variables[27]==0 && !$game_switches[62]
     
    1,224
    Posts
    10
    Years
  • 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]
     
    16
    Posts
    12
    Years
    • Seen Dec 13, 2016
    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