• 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?".
  • Forum moderator applications are now open! Click here for details.
  • 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
12
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:

Ego13

hollow_ego
311
Posts
6
Years
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
 

Chdonga

Pixel Artist/Spriter
24
Posts
12
Years
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.
 
1,669
Posts
8
Years
  • Age 23
  • Seen yesterday
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.
 

Chdonga

Pixel Artist/Spriter
24
Posts
12
Years
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?
 
1,669
Posts
8
Years
  • Age 23
  • Seen yesterday
Would that mean "if $game_variables[000]" would look for variable -1?

0 is 0 regardless of base. Also, using a negative index causes it to add the length of the array, so it would return the value of variable 100. Variable 0 is unused, I think.
 
Back
Top