[ASM & Hex] ASM Variables Question - The PokéCommunity Forums

ASM & Hex ASM Variables Question

Started by MagallanesX July 3rd, 2020 10:20 AM
  • 2 replies
Seen September 8th, 2020
Posted August 24th, 2020
15 posts
1.9 Years
Where or how are global variables stored in Fire Red?
If I for example, wanted to know where to find the variable that had my rival select a starter that was strong against my selected Pokemon.

Where are the player's current badges stored?

Where is the data for all of the Pokemon in the party, such as their typing.

Where is the data stored for the opponent's Pokemon party?

I would like to see where I can find this information to start more advanced rom hacking with the tools given to me by a user who answered my last question.

Thank you!
Katones City
Seen 1 Day Ago
Posted January 7th, 2022
62 posts
5.6 Years
Here is a post with the RAM layout for Fire Red. Most of the data you are looking for are in various memory addresses in the RAM as they are temporary things that the game overwrites over time as necessary.

For individual answers of your questions:
the variable that had my rival select a starter that was strong against my selected Pokemon: By default, Fire Red uses the variable 0x4001 to determine which pokeball you picked in Oak's lab. It is equal to 0 if you picked Bulbasaur, 1 if you picked Squirtle, and so on. However, 0x4001 is a temporary/disposable variable that the game uses only to apply movements for your rival in the lab at the start of the game during the starter selection. The game also uses 0x4031 to determine which starter you picked. (Credits to this post)

As for the memory address of where the values of these variables are stored, I myself am unsure (still a novice here). They are apparently DMA-protected. DMA stands for Dynamic Memory Allocation. That is their memory addresses are dynamic instead of static. If they were static instead, there would have been fixed memory addresses for them using which you could change or manipulate their values through your scripts or ASM routines.

the player's current badges stored: IIRC, there are no variables of any kind in Fire Red that keeps track of HOW MANY badges you have. Instead, the game checks various flags to see WHETHER you have a particular badge or not. Here is a list of the flags that get set once you get the corresponding badges:
820 If set, the player has the BOULDERBADGE.
821 If set, the player has the CASCADEBADGE.
822 If set, the player has the THUNDERBADGE.
823 If set, the player has the RAINBOWBADGE.
824 If set, the player has the SOULBADGE.
825 If set, the player has the MARSHBADGE.
826 If set, the player has the VOLCANOBADGE.
827 If set, the player has the EARTHBADGE.

Technically, you could use one of the temporary/disposable variables to keep track of how many badges a player has. Just at every gym battle script, add something like "addvar 0x4069 0x1" right after when the gym flag is set. Then 0x4069 will have the value equal to the number of gym badges the player has. You could use a different variable though but make sure it is not used for other stuffs in the game and make sure it is safe. Just in case you don't know: variables from 0x4000 to 0x4100 are the safe ones IIRC. Still cross check from other Pokecommunity posts!

the data for all of the Pokemon in the party, such as their typing: There is the memory address for the data for each of the player's Pokemon and also each of the opponent's Pokemon mentioned in the very first link of my reply. Still for clarity:
The data for trainer's party Pokemon is stored at 0x02024284 in the RAM. 0x0202402C contains the data for the wild Pokemon / opponent's Pokemon. Each Pokemon's data takes 100 bytes of space. You can find even more details about them from these two Bulbapedia pages:
Pokémon data structure in Generation III
Pokémon data substructures in Generation III

the data stored for the opponent's Pokemon party: same places as above

I hope these helps! Feel free to ask for further simplification!


Seen June 8th, 2021
Posted July 19th, 2020
11 posts
3.6 Years
Hi! I want to ask something about RAM variables.

How can I reach the RAM variables on scripts? I used this script in my game but it didn't work.

setvar 0x4001 0x00
compare 0x4001 0x0300500C
if 0x1 goto @true
if 0x5 goto @false
I got a "Wrong parameter type" error on XSE. Am I missing something?

I am still a newbie on this. Your help is greatly appreciated ^^