Variable (scripting): Difference between revisions
(Created page with "'''Script variables''' consist on a memory region where numeric values can be stored and operated by the game. Each variable is a {{u16}} value that can be dynamically read and written, not only by the scripts but also from the main code. Most of the variables are saved in the savegame file, allowing us to use them as checkpoints in the gameplay, to control the scripts behaviour during the story and to enable or disable certain events. There is a limited number of usable...") |
No edit summary |
||
Line 76: | Line 76: | ||
| This variable stores the ID of the overworld to whom the player talked to start the script | | This variable stores the ID of the overworld to whom the player talked to start the script | ||
|} | |} | ||
[[Category:Gen_IV]] | |||
[[Category:Scripting]] |
Latest revision as of 10:55, 14 August 2022
Script variables consist on a memory region where numeric values can be stored and operated by the game. Each variable is a u16 value that can be dynamically read and written, not only by the scripts but also from the main code. Most of the variables are saved in the savegame file, allowing us to use them as checkpoints in the gameplay, to control the scripts behaviour during the story and to enable or disable certain events. There is a limited number of usable variables in the ROM, depending on the game version, as well as there is a limited range of values that a variable can hold (from 0 to 65535). Every variable in the variable memory region is referenced with an unique ID, which allows to access both their memory address and their current value.
Variables are divided in two groups, public variables and private variables. Private variables only exist while a script is being executed, excepting level scripts, and they can be no longer accessed after the script has ended. Public variables keep their value when no script is being executed, they can be accessed at any moment in the game, and most of those variables keep their values when the map is changed or the game is saved and quit.
Pokémon DPPt
There are 288 public variables in Pokémon Diamond, Pearl and Platinum (256 in Pokémon Diamond and Pearl Japanese versions). On the other hand, there are 14 private variables. They are used as following:
Group | # | Range name | Function |
---|---|---|---|
Public variables | 0x4000 - 0x401F | Temporary variables | These variables are reset to zero when the map is changed |
0x4020 - 0x402F | Overworld variables | Overworlds whose sprite is between 101 and 116 have a sprite corresponding to the values of these variables | |
0x4030 - 0x406F | Special variables | These variables are actively modified by the game main code | |
0x4070 - 0x411F | Normal variables | Variables which are not accessed by the game main code, but only by scripts | |
Private variables | 0x8000 - 0x800C | Private variables | These variables are only accesible when a script is running |
0x800D | Invoking overworld ID | This variable stores the ID of the overworld to whom the player talked to start the script |
Pokémon HGSS
There are 368 public variables in Pokémon HeartGold and SoulSilver. On the other hand, there are 14 private variables. They are used as following:
Group | # | Range name | Function |
---|---|---|---|
Public variables | 0x4000 - 0x401F | Temporary variables | These variables are reset to zero when the map is changed |
0x4020 - 0x402F | Overworld variables | Overworlds whose sprite is between 101 and 116 have a sprite corresponding to the values of these variables | |
0x4030 - 0x406F | Special variables | These variables are actively modified by the game main code | |
0x4070 - 0x416F | Normal variables | Variables which are not accessed by the game main code, but only by scripts | |
Private variables | 0x8000 - 0x800C | Private variables | These variables are only accesible when a script is running |
0x800D | Invoking overworld ID | This variable stores the ID of the overworld to whom the player talked to start the script |