Quote:
Originally Posted by Touched
Flags are booleans. They're for when you want a simple true/false, yes/no or on/off condition, e.g. "has the player completed this event?", "is this NPC visible?", "do I have this gym badge?", etc. As you can see, these are binary (two choices) questions, so it makes sense to represent them that way in memory to save space. As each flag only uses one bit, you can have 16 flags in the space that a variable uses. Most events are binary, so this turns out to be pretty useful.
Variables are for when you want to store more information, such as a step counter, the non-binary state of some event, the X/Y position of the player, etc. You can perform arithmetic on variables (only add/subtract with default script commands). Variables are in a sense, more powerful than flags - but in most cases they are not needed. Variables are 2 bytes (16 bits) and thus can store values from 0 to 65535 inclusive (2^16-1).
There are some places you absolutely need to use one or the other. Flags can be attached to NPCs which then control their visibility when you toggle them. Variables control script triggers and level scripts.
The question you need to ask when choosing is "Can this be represented as a binary choice?". If the choice is between exactly 2 distinct things, a flag is a good choice. However, if you need 3 or more options or need to perform arithmetic, use a variable. You can also use some combination of the two (one flag and one variable, two flags, etc.) if your needs are more complex.
|
Thank you so much for clearing that up for me.