• 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!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll 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.

[v17.2] Get scripts to check variable

Chdonga

Pixel Artist/Spriter
  • 24
    Posts
    13
    Years
    I'm trying to make a difficulty mode that uses a variable. Since global switches will always be seen as false according to the wiki.

    This is the outcome I want:

    Battle:
    • If variable 14 = 2, Set battle style
    • If variable 14 = 1, Switch battle style, but it won't tell you the opponent's next Pokemon.
    • If variable 14 = 0, normal Switch battle style.

    Storage:
    • If variable 14 = 2, Pokemon won't be healed when you place them in a box, and something you just caught won't get healed when it gets sent to storage.
    • If variable 14 != 2, then it's a normal storage system.

    These are the changes I've made to the scripts (highlighted):

    PokeBattle_Battle
    Spoiler:

    Pokemon_Storage
    Spoiler:

    PScreen_PokemonStorage
    Spoiler:



    It doesn't seem to matter what I change the value to. It doesn't seem to matter if I change it to "if... == 2" or "if... = 2". The game always treats the value like it's set to 2. And I'm not that sadistic. How do I fix this?
     
    Last edited:
    first thing you need to know: if you want o compare a variable with somethin you use
    Code:
    ==
    So saying
    Code:
    if $game_variables[014]==1
    means: "If the variable number 14 is equa to 1"
    While
    Code:
    if $game_variables[014]=1
    means: "if you set variable number 14 to 1" which will always result in this condition to be considered true.

    Next thing to know: If you want to check if a variable is not euqal to something you use
    Code:
    !=
    So saying
    Code:
    if $game_variables[014]!=2
    means: "If the variable number 14 is not equal to 2"
    while
    Code:
    if !$game_variables[014]==2
    means: "if you invert "game variable number 14 is equal to 2""
    See the exclamation mark at the beginning is a negation. So if you put it like in your code and $game_variables[014] is not equal to 2 then it would return true and therefore execute this code
     
    I made those changes but now it only acts as if the value is 0. Should I add a "return" anywhere in the code? I don't quite understand its purpose but I see it used in a lot of "if" functions.
     
    I made those changes but now it only acts as if the value is 0. Should I add a "return" anywhere in the code? I don't quite understand its purpose but I see it used in a lot of "if" functions.

    Okay, I think the issue here is because of the 014 for the variable number. The reason? Ruby interprets it as an octal number, specifically 12. You aren't checking variable 14, but rather the value of variable 12, which is the reason for the strange results.

    You can try it for your sell by putting p 014 in a script command.
     
    Okay, I think the issue here is because of the 014 for the variable number. The reason? Ruby interprets it as an octal number, specifically 12. You aren't checking variable 14, but rather the value of variable 12, which is the reason for the strange results.

    You can try it for your sell by putting p 014 in a script command.

    Well, I changed it to "if $game_variables[14]" and now everything works. Funny how an unnecessary zero can cause everything to screw up.

    So the extra zero must've caused it to be read as an octal number. Would that mean "if $game_variables[000]" would look for variable -1?
     
    Back
    Top