Flags are basically markers that are associated with objects that can be marked on or off. They are called for by a value between 0 and 32.
So basically if you set an objects Flag 1 to On, then you can use the condition "Is Object Flag 1 On" and it will fire.
The 2 major significance in flags are basically 1, they are a lot more simple then alterable values, since they can be more specific to simply being On and Off, while alterable values are better suited for unlimited values. And one major significance to flags is simply that they can be toggled. This takes a way a small amount of complexity in the code, which over time, can mean dropping a good 2 to 10 or more events from your code if your game gets big.
Sorry, this post is kind of long for something so simple. I assure you, flags aren't complex at all, even if I kind of made them seem like it. They are just markers that turn On and Off.
Flags are very simply a way of keeping track of things. You can set a flag to being on or off.
For instance, you can use flags to determine whether or not you have selected something that you want to cling to the mouse.
Upon clicking Object A > Set Object A's Flag 0 to on.
Object A's flag 0 is on > SET X Position to XMouse and Y position to YMouse.
There are an infinite amount of things you can use flags for. Just remember that if you want to keep track of anything, you can use a flag. (BTW, I put flag 0 simply because it is the first available one.)
Hope that makes sense.
EDIT: Whoops, BrandonC beat me to it. But really, they are fairly simple. You can use them for literally anything and everything. Essential to any mid-sized game, probably.
Edited by OMC
Deleted User
10th January, 2009 at 04:19:00 -
I'm used to hearing them being compared to a light switch. Think of them like that.
Flags are just variables that can only hold two values (on and off)
Objects can have up to 32 flags I think, so say you are trying to edit an "enemy" object's 14th flag.
You could use the flag to say whether or not the enemy has seen the player, so it could be something like this:
+Enemy sees player
> turn flag 14 of enemy on
+Enemy can't see player
> turn flag 14 of enemy off
+ Enemy's flag 14 is on
> Chase the player and kill him
That's pretty self explanatory...
You can also toggle flags, which if a flag is on, changes it to off and vice-versa. So you could use for something like this:
+User clicked on light-switch
> toggle flag 7 of light-switch
+ flag 7 of light-switch is on
>Display a bright light
+ flag 7 of light-switch is off
>Display darkness
That's also quite self explanatory.
On important thing to remember about flags is that they are off by default, so in this case, before the user has clicked the light-switch, there is darkness being displayed because flag 7 is set to off by default and the start of the frame.
Flags are handy because they don't use as much memory as alterable values and are easily toggled. If you've ever learnt a programming language like C++ or Java, flags are kind of the MMF2 equivalent of boolean variables, which only return a 0 or 1 value.
I just tried to edit my post as "Looks like you guys beat me to it" but by the time I'd written that, Adam had already made a reply, so I guess I'll say:
Originally Posted by jneumann1 I'm used to hearing them being compared to a light switch. Think of them like that.
Yes, that's exactly how I think of them. Sometimes people make things seem so much more complex than they are.
Because some people have enough respect to share their critical thinking with others. It's just not always wanted, or presented in the way that any sane person would easily be able to comprehend. You make it sound like a bad thing.
But yes, flags at their most simple form, are best compared to a light switch.
Just came up with another question. How do you get to the flags for an item? Here's an example, I'm trying to make a double jump for a character, making it so when it reaches its apogee it tuns on its "Jump" flag and jumps one more time. Is that the best way to do that, or do you have any other suggestions?
The conditions for flags are listed under "alterable values," while events are listed under "flags."
To make a reliable double jump, I find that it's best to use a combination of an alterable value and flags. Use the flags to denote that you've jumped, and the alt value to measure when you're able to make the second jump. Using two flags gives you the ability to denote that you made the first jump, if you don't want players to walk over an edge and be able to double jump away.
There are multiple ways to do a double jump, though. I don't use the method I mentioned, because I find it rather primitive.
EDIT: I should point out that if you're using a custom platform movement that uses an alterable value to control "gravity," then you can just make a range check on that value instead of using a new value.
Sometimes it's better to write the code yourself and figure it out. It's easier to understand if you write it yourself.. but better to write it on paper first, in English (not code) if you can't figure out what to do.
(This does the first jump. The flags check if the character is already jumping/double jumping)
On Pressing jump
AND Flag 0 of Character is off
AND Flag 1 of Character is off
> Turn Flag 0 of Character on.
> [Jumping code]
(This does the code for the second jump. It only works if the character hasn't double jumped)
If Flag 0 on
AND Flag 1 off
AND On pressing jump:
> Turn Flag 1 on
> [Double jump code]
(On hitting the ground, reset flags)
If Character touches ground:
> Turn Flag 0 off
> Turn Flag 1 off
Also, on the topic of flags, you should know that there are only 32 flags in MMF2. From Flag 0 to Flag 31. The others are fake, trying to confuse you. Maybe you knew that, but I didn't know it, until I messed up my game using something like Flag 322
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.