Thread: [Tutorial] XSE Scripting Tutorial
View Single Post
Old 1st March 2018, 10:17 PM  
Join Date: Nov 2013
Posts: 33

Flags & Variables

Think of a flag as an on or off switch - it can be either 1 "ON" or 0 "OFF". Think of a variable as a better version of a flag - it can't just be 0x0 or 0x1 "on or off"- but holds any value between 0x0 and 0xFF, hence the name "variable". Both are crucial for creating your gameplay events, but we'll focus on flags for now:
Originally Posted by Avara
setflag 0x[Flag Number]
Originally Posted by Avara
clearflag 0x[Flag Number]

Here is a list of "special" flags for each game - these have different in-game functions when set, or "ON":

0x820 – Activates First Badge
0x821 - Activates Second Badge
0x822 - Activates Third Badge
0x823 - Activates Fourth Badge
0x824 - Activates Fifth Badge
0x825 - Activates Sixth Badge
0x826 - Activates Seventh Badge
0x827 - Activates Eighth Badge
0x828 - Activates Pokémon Menu
0x829 - Activates Pokédex Menu
0x82F - Activates Running Shoes

0x860 - Activates Pokémon Menu
0x861 - Activates Pokédex Menu
0x862 - Activates Pokénav Menu
0x867 - Activates First Badge
0x868 - Activates Second Badge
0x869 - Activates Third Badge
0x86A - Activates Fourth Badge
0x86B - Activates Fifth Badge
0x86C - Activates Sixth Badge
0x86D - Activates Seventh Badge
0x86E - Activates Eighth Badge
0x8C0 - Activates Running Shoes

karatekid552 and DavidJCobb did an excellent job of referencing every flag and variable in the FireRed ROM and what they do. If you hack FR, this documentation will be invaluable to you. Emerald hackers will find this information on flags/vars useful.

Let's move on to variables.
Originally Posted by Avara
setvar 0x[Variable Number] 0x[Value To Set To]
As you could probably guess, the setvar command sets your chosen variable to your chosen value. If you want to add to a variable's existing value, we use addvar:
Originally Posted by Avara
addvar 0x[Variable Number] 0x[Value To Add To Var]
Let's say I wanted to increase the value of 0x40D1 by 10 - I'd have addvar 0x40D1 0xA. Similarly, if I wanted to subtract from a variable's existing value, I'd use subvar, which is set up exactly the same:
Originally Posted by Avara
subvar 0x[Variable Number] 0x[Value To Subtract From Var]
What if we want to copy the value of one variable into another?
Originally Posted by Avara
copyvar 0x[Variable 1] 0x[Variable 2]
The above line just takes the value of Var #1 and stores it in Var #2.
Now that we know how to add to, subtract from and set a variable, how do we check it?
Originally Posted by Avara
compare 0x[Variable Number] 0x[Value To Check For]
if 0x[More/Less/EqualTo] goto @pointer
Let's say we want to check if the var 4011's value is 3, for example:
Originally Posted by Avara
compare 0x4011 0x3
if 0x1 goto @pointer
What we're telling the script to do here is check that 4011 is equal to 3, and if it is to go to @pointer.
Originally Posted by Avara View Post
0x0 = Lower Than
0x1 = Equal To
0x2 = Greater Than
0x3 = Lower Than or Equal To
0x4 = Greater Than or Equal To
Avara is offline   Reply With Quote
Likes Lunos liked this post