Overworld Scripting ‐ Flags - haven1433/HexManiacAdvance GitHub Wiki

Click to return to the main scripting page

A Flag is a value in your save file that answers a single yes-or-no question about your current progress.

  • Have you picked up the item?
  • Have you collected the badge?
  • Have you answered the riddle?

Another such question is "have you beat this trainer?" but since there are so many trainers, they get their own set of flags.

You can see the list of all flags and what they're used for in the vanilla games within the Help menu.

Example Script using a Flag

In this example, you want an NPC to give you an item, but only once. So the outline for the script might look like:

if the flag is set, goto bottom
  "Here you go!"
  add item
  set flag
bottom:
  "Enjoy!"

Here's what that might look like as an actual script:

image

Things to note:

  • The flag is checked at the beginning of the script so you can skip to the end if the script has run before.
  • The flag is set as you get the item, since that's what we want to track.
  • The script still needs all the standard lock/faceplayer/release/end commands that you'd expect.

Using a flag to show/hide an NPC

Each object event can be hidden or shown using a flag.

image

When the flag is 'set', the NPC will be hidden. When the flag is 'clear', the NPC will be shown. This is how items in the overworld work: whenever you pick them up, their flag gets changed to 'set'. If you later clear the flag in another script, it'll make the item show again.

Choosing an unused flag

While writing a command that uses flags, a button will appear next to your cursor that lets you choose an unused flag.

image

While the button is showing, you can also press Ctrl+U ("U" for "Unused").

Temporary Flags

Flags 0x0001 through 0x001F get reset when you switch maps. This makes the flags good for events that you want to repeat, like a trainer that you can re-battle every time you re-enter the map, or a breakable rock that you want to come back.

Finding where a flag is used

Any time you see a flag used in a script, you can right-click the flag to get an option to find where that flag is used in the game.

image

The results will include:

  • Any command that uses that flag, such as setflag, clearflag, or if.flag.set.goto.
  • Any object that uses that flag to show/hide itself.