• 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.

Flags, Vars, & Script Tiles

AkameTheBulbasaur

Akame Marukawa of Iyotono
409
Posts
10
Years
Okay thanks! So if I don't have any vars, then it'll be fine. My hack is 99.9% complete so I didn't want to have to do a bunch of rearranging if I didn't have to. I ever knew how to use vars well anyway. Again, thanks for clearing that up.
 

karatekid552

What happens if I push it?....
1,771
Posts
11
Years
Okay thanks! So if I don't have any vars, then it'll be fine. My hack is 99.9% complete so I didn't want to have to do a bunch of rearranging if I didn't have to. I ever knew how to use vars well anyway. Again, thanks for clearing that up.

but, but, vars are sooo much more useful.:P Umm, some vars, like 0x4000->0x4005 are temporary, meaning that area of ram resets on warp. So, those flags will also reset. Also, certain events are solely controlled by vars, so be careful and so some math to see which var you are corrupting.
 
30
Posts
10
Years
  • Age 33
  • Seen Sep 12, 2015
Hi

Im browsing around, trying to learn about vars, flags and all this stuff. I totally get the whole idea behind your tutorial, but I have some tiny questions about how it works.

setvar 0x4050 0x1 <-- What happens with the var here?? Does the 0x1 change the var number, or is it like a "toggle" inside the variable? The var value you set, is that what you set the variable to, or is it what you set the game to check the variable for? Or rather, with 0000 in this box, and you play the game - is the variable now set to 0x0, or does it compare the variable to 0x0 (because you entered 0000)? And is it a default value for this?

I hope what Im asking is not too confusing :P its just the basic functionality that Im missing.
 

karatekid552

What happens if I push it?....
1,771
Posts
11
Years
Hi

Im browsing around, trying to learn about vars, flags and all this stuff. I totally get the whole idea behind your tutorial, but I have some tiny questions about how it works.

setvar 0x4050 0x1 <-- What happens with the var here?? Does the 0x1 change the var number, or is it like a "toggle" inside the variable? The var value you set, is that what you set the variable to, or is it what you set the game to check the variable for? Or rather, with 0000 in this box, and you play the game - is the variable now set to 0x0, or does it compare the variable to 0x0 (because you entered 0000)? And is it a default value for this?

I hope what Im asking is not too confusing :P its just the basic functionality that Im missing.

A var always starts at 0x0000. If you have ever programmed, you have used vars. If you have ever done algebra, you have used vars. Vars are variables. They can be anything. In high-level programming, they have names like "place_to_store_stuff" and you can set it to whatever you want. In math, it is almost always X.

Now, a variable is a memory location that you use to store data in. Here, these are two byte data locations accessed by their number, which in this case is 0x4050. So, by doing setvar 0x4050 0x1, you are storing 01 at the location of var 0x4050 for later access. Think of the var number like a book cover on an encyclopedia. Most of the time with encyclopedia volumes, all there is, is a name and a number on the cover. inside is what counts. So here, setvar 0x4050 0x1, is essentially changing the pages of that book.

Understand?
 
30
Posts
10
Years
  • Age 33
  • Seen Sep 12, 2015
A var always starts at 0x0000. If you have ever programmed, you have used vars. If you have ever done algebra, you have used vars. Vars are variables. They can be anything. In high-level programming, they have names like "place_to_store_stuff" and you can set it to whatever you want. In math, it is almost always X.

Now, a variable is a memory location that you use to store data in. Here, these are two byte data locations accessed by their number, which in this case is 0x4050. So, by doing setvar 0x4050 0x1, you are storing 01 at the location of var 0x4050 for later access. Think of the var number like a book cover on an encyclopedia. Most of the time with encyclopedia volumes, all there is, is a name and a number on the cover. inside is what counts. So here, setvar 0x4050 0x1, is essentially changing the pages of that book.

Understand?

Thanks for reply :)

I have had some basic Java and C++, so I know what a variable is.. Very basic tough! But yeah, I think I get it now! Just to be 100% sure, you could say setvar 0x4050 0x1 would be int 4050 = 1 basically? And everything from 0x0000 to 0xFFFF are variables the game can use?

I guess what made me a bit confused is the random use of 1 and 4 numbers as the value, which probably is very common in languages I havent used yet. What is the value set to; 0x0001 or 0x1000?
 

karatekid552

What happens if I push it?....
1,771
Posts
11
Years
Thanks for reply :)

I have had some basic Java and C++, so I know what a variable is.. Very basic tough! But yeah, I think I get it now! Just to be 100% sure, you could say setvar 0x4050 0x1 would be int 4050 = 1 basically? And everything from 0x0000 to 0xFFFF are variables the game can use?

I guess what made me a bit confused is the random use of 1 and 4 numbers as the value, which probably is very common in languages I havent used yet. What is the value set to; 0x0001 or 0x1000?

On the first part, you are right. That is how it works.

Second, did you even read the Vars section of this tutorial? I clearly outlined what variables could be used.

The 1s and 4s aren't random, the vars are incremented over events. Normally, GF only uses a var 4 times, so the first time it is used, it is set to 1, then events take place and eventually it ends up being set to 4 and stays there.

The value will be set to 0x0001, but if you look at it in the ram, it will be 0100. This is only for storage purposes. Whenever you access it, it will automatically be loaded at 0x0001.

------
In case you wanted to know, GBA roms are written in C.
 
30
Posts
10
Years
  • Age 33
  • Seen Sep 12, 2015
On the first part, you are right. That is how it works.

Second, did you even read the Vars section of this tutorial? I clearly outlined what variables could be used.

The 1s and 4s aren't random, the vars are incremented over events. Normally, GF only uses a var 4 times, so the first time it is used, it is set to 1, then events take place and eventually it ends up being set to 4 and stays there.

The value will be set to 0x0001, but if you look at it in the ram, it will be 0100. This is only for storage purposes. Whenever you access it, it will automatically be loaded at 0x0001.

------
In case you wanted to know, GBA roms are written in C.

Allright, Im futher into this stuff now :) Might aswell look some into C! Thanks a bunch for your help :)

PS: I ment what variables the game have access to, not which I can use.. But its obvious now anyways :)
 

karatekid552

What happens if I push it?....
1,771
Posts
11
Years
Allright, Im futher into this stuff now :) Might aswell look some into C! Thanks a bunch for your help :)

PS: I ment what variables the game have access to, not which I can use.. But its obvious now anyways :)

Oh, okay. In that case, anything over 0x3FFF will be read as a variable by the game. Anything below is read as a static number. This is how script commands are able to use both variables and static numbers without changing syntax.
 

Le pug

Creator of Pokémon: Discovery / Fat Kid
870
Posts
10
Years
uh ive been told many times anything from 900 to like 1F00 or something are safe flags and using them ive had no problem so why are you saying theyre not safe?
 

karatekid552

What happens if I push it?....
1,771
Posts
11
Years
uh ive been told many times anything from 900 to like 1F00 or something are safe flags and using them ive had no problem so why are you saying theyre not safe?

Because I have physically seen the RAM corruption that using them causes. To prove this point, I want you to run this script:

Code:
#Dynamic 0x800000
#org @start
setvar 0x4000 0x0
compare 0x4000 0x0
if 0x1 jump @safe
setflag 0x900
compare 0x4000 0x0
if 0x1 jump @safe
end

#org @safe
msgbox @safe_msg 0x3
return

#org @safe_msg
= var 0x4000 is safe

#org @corrupted
msgbox @corrupted_msg 0x3
return

#org @corrupted_msg
= var 0x4000 has been corrupted

You will notice that the safe message only plays before flag 0x900 has been set. It does not run twice. This is because flags 0x900->0x90F exist in the RAM that holds var 0x4000. The RAM overlaps, because in Assembly, unlike high-level languages, there is no concept of Scope. Scripting is calling certain assembly functions and passing them parameters. Because there is no scope, you can pass them anything. Doesn't mean it is good.
 

RichterSnipes

Not even a nibble...
513
Posts
12
Years
  • Age 30
  • USA
  • Seen Dec 1, 2023
Is there any indicator on what flag values in the 300s are used for, if anything? When I was testing flag values for a completed save file a couple of weeks ago, all the values I used in the 300s (which I think was the vast majority of them) were cleared in the game. Are they only set in specific circumstances then cleared right afterwards (like in certain screens), or is there something else about them?

Great thread, BTW. Anyone working on hacks nowadays should be wary of what specific flag values they add to the game.
 

karatekid552

What happens if I push it?....
1,771
Posts
11
Years
Is there any indicator on what flag values in the 300s are used for, if anything? When I was testing flag values for a completed save file a couple of weeks ago, all the values I used in the 300s (which I think was the vast majority of them) were cleared in the game. Are they only set in specific circumstances then cleared right afterwards (like in certain screens), or is there something else about them?

Great thread, BTW. Anyone working on hacks nowadays should be wary of what specific flag values they add to the game.

I honestly don't know about those flags. Why not try and set them, then see if they get cleared on warp? My best guess is that they are temporary.
 

RichterSnipes

Not even a nibble...
513
Posts
12
Years
  • Age 30
  • USA
  • Seen Dec 1, 2023
I honestly don't know about those flags. Why not try and set them, then see if they get cleared on warp? My best guess is that they are temporary.
Okay, so I was actually crazy enough to test this out as thorough as I could.

I set several flags with various values in the 300s in my hack (in this case, through starting/ending events I put in the game). I then tested them immediately afterwards to make sure they stay set. The only things keeping them set are the scripts themselves; there are no map scripts that keep them that way. I then proceeded to access every warp easily available in the game. Every map, every building, every cave, every teleporter...everything. I even beat the Pokémon League just to make extra sure. I also flew to each place in the game. Upon checking back at my events, the flags remained set.

So, unless by pure coincidence every last one of those flags in the 300s that I set are cleared by warps on the S.S. Anne, I can say within reason that the flags in the 300s are not cleared when warping.
 

karatekid552

What happens if I push it?....
1,771
Posts
11
Years
Okay, so I was actually crazy enough to test this out as thorough as I could.

I set several flags with various values in the 300s in my hack (in this case, through starting/ending events I put in the game). I then tested them immediately afterwards to make sure they stay set. The only things keeping them set are the scripts themselves; there are no map scripts that keep them that way. I then proceeded to access every warp easily available in the game. Every map, every building, every cave, every teleporter...everything. I even beat the Pokémon League just to make extra sure. I also flew to each place in the game. Upon checking back at my events, the flags remained set.

So, unless by pure coincidence every last one of those flags in the 300s that I set are cleared by warps on the S.S. Anne, I can say within reason that the flags in the 300s are not cleared when warping.

You went a little overkill.:p Most warps work the same. Now, you just need to make sure nothing else uses that area of RAM. There is a reason GF doesn't use those flags. (hopefully, the compiler just skipped those.:p) Now, clear them all, and periodically check if they are set.
 

RichterSnipes

Not even a nibble...
513
Posts
12
Years
  • Age 30
  • USA
  • Seen Dec 1, 2023
You went a little overkill.:p Most warps work the same. Now, you just need to make sure nothing else uses that area of RAM. There is a reason GF doesn't use those flags. (hopefully, the compiler just skipped those.:p) Now, clear them all, and periodically check if they are set.
Whoops. Which area of RAM would I be looking at for those flags?
 

haven1433

Modder / Programmer
42
Posts
10
Years
  • Age 35
  • Seen Jan 16, 2024
Very detailed stuff! I'm working on a hack, and was very confused as to how to figure out which flags were used and which are available. You answered all that, so thanks!
 
252
Posts
10
Years
  • Age 27
  • Seen Jul 6, 2019
Hey karatekid552 I have a question.
I was looking through Prof Oak's scripts in Pallet Town (The scripts where he brings you to his lab and gives you pokemon).
And I noticed flags like 0x2CF and 0x247, which were listed as unknown on your list.
And somewhere in the comments, you said this.
The unknown, is just that, unknown. There are quite a bit of things like this in the coding and are often called fillers or constants and they don't do anything other than separate data.
So does that mean that I could possibly skip those flags if I wanted to re-create Oak's script?
 

karatekid552

What happens if I push it?....
1,771
Posts
11
Years
Hey karatekid552 I have a question.
I was looking through Prof Oak's scripts in Pallet Town (The scripts where he brings you to his lab and gives you pokemon).
And I noticed flags like 0x2CF and 0x247, which were listed as unknown on your list.
And somewhere in the comments, you said this.

So does that mean that I could possibly skip those flags if I wanted to re-create Oak's script?

Lol, that quote is referencing the unknown bytes in script tile making, not vars or flags.:P

Either way, if you are re-scripting the entire game, you pick the flags and vars, so it doesn't matter what GF's compiler used. The only flags that matter are those in the 800s, since those control the necessary in game stuff.
 
252
Posts
10
Years
  • Age 27
  • Seen Jul 6, 2019
Lol, that quote is referencing the unknown bytes in script tile making, not vars or flags.:P
Either way, if you are re-scripting the entire game, you pick the flags and vars, so it doesn't matter what GF's compiler used. The only flags that matter are those in the 800s, since those control the necessary in game stuff.

Oh ok I see.
I'm trying to recreate some of the game's scripts as practice, since I'm still fairly new to scripting.
 

M0ZEPH

Formally 'Resultz' - Returned!
76
Posts
10
Years
  • Age 31
  • Seen Mar 30, 2014
You say only these vars x-y are safe, yet you say they can be any value upto 65000, does that mean every other one is used, or am I missing something major here?
 
Back
Top