M6: Flag macro conditional and commands

Flags allow custom user-modifiable state to be introduced into macro command options in M6 macros (and other contexts where extended conditionals can be used). For example, the macro below will, when triggered while holding the Control key, switch between casting Battle Shout and Commanding Shout.

/cycleflag [mod:ctrl] command /cast [flag:command] Commanding Shout; Battle Shout

Checking flag state

The [flag] extended conditional can be used to query flag state. You can define any number of flags, each identified by a name. Flags that haven't been assigned a value, or have been assigned the value 0, are considered cleared; flags that have been assigned any value except 0 are considered set. Some examples:

[flag:foo]
Satisfied when the flag named foo is set.
[noflag:foo]
Satisfied when the flag named foo is cleared.
[flag:foo=1]
Satisfied when the flag named foo is set to value 1.
[noflag:foo=1]
Satisfied when the flag named foo is not set to value 1.
[flag:foo=0]
Satisfied when the flag named foo is cleared.
[flag:foo=bar]
Satisfied when the flag named foo is set to value bar.
[flag:foo/baz]
Satisfied when one or both of the flags foo and baz are set (i.e. set to a non-0 value).

Changing flag state

You can use the following commands in M6 macros to modify flag conditional state:

  • /setflag: sets a flag to a specified value, or clears a flag.
  • /cycleflag: modifies flag state based on its current value.
  • /randflag: sets a flag to a random value.

All three evaluate their arguments as secure command options, allowing the use of extended conditionals.

/setflag

Sets a flag to a specified value, or clears a flag. The general syntax is /setflag name=value. There are a number of shortcuts among the examples below:

  • /setflag foo=1 sets the flag named foo to value 1.
  • /setflag foo=bar sets the flag named foo to value bar.
  • /setflag foo=0 clears the flag named foo.
  • /setflag foo sets the flag named foo (to value 1).
  • /setflag foo= clears the flag named foo.

/cycleflag

Modifies flag state based on its current value. This can be used to toggle the flag state, or to go through a number of numeric values in sequence. The general syntax is /cycleflag name<ceiling+step where ceiling and step are integers. There are a number of shortcuts described among the examples below:

  • /cycleflag foo toggles flag named foo: if it was set, it will be cleared, if was cleared, it will be set.
  • /cycleflag foo<3 sets the value of the flag named foo to its current value plus 1 modulo 3, clearing the flag if this value is 0. In isolation, this produces the cycle: cleared → 1 → 2 → cleared.
  • /cycleflag foo<5+2 sets the value of the flag named foo to its current value plus 2 modulo 5, clearing the flag if this value is 0. In isolation, this produces the cycle: cleared → 2 → 4 → 1 → 3 → cleared.
  • /cycleflag foo<5-2 sets the value of the flag named foo to its current value minus 2 modulo 5, clearing the flag if this value is 0. In isolation, this produces the cycle: cleared → 3 → 1 → 4 → 2 → cleared.

/randflag

Sets a flag to a random value within the specified range. The general syntax is /randflag name<ceiling where ceiling is an integer; the flag with the specified name is set to a random non-negative integer smaller than ceiling (if 0 is chosen, the flag is cleared).

  • /randflag foo randomly sets (to 1) or clears the flag named foo.
  • /randflag foo<2 randomly sets (to 1) or clears the flag named foo.
  • /randflag foo<4 randomly sets (to either 1, 2, or 3) or clears the flag named foo.