Command:/if

From the wonderful RedGuides Wiki

This command is added by MacroQuest

Syntax Key
Notation Description
Text without brackets or braces Required items
<Text inside angle brackets> Placeholder for which you must supply a value
[Text inside square brackets] Optional items
Vertical bar (|) Separator for mutually exclusive items; choose one
{Text | inside | braces} Set of required items; choose one
Ellipsis () Items that can be repeated
Syntax /if <formula> {commands} [else {commands}]
Description This will run all commands between the braces ( {} ) if formula evaluates to something other than 0.
  • Formulas are numeric operations ONLY. You must use MQ2Data string comparison to turn string comparisons into

numeric operations (eg. Using .Equal or .NotEqual).

  • You can use && and || freely within formula, which will be evaluated down to a single term before proceeding.
  • Multiple commands may be included within the braces.
  • There is no need to use ${Math.Calc[]} in /if statements, since the formula is automatically converted into

numeric operations.

  • Else and else /if can be used to further refine how/which commands are run.
  • This will not work on some older versions of MQ2 (IE Jan 25, 2004) You will get a "Failed to parse /if command"

Options

Examples

/if (${Target.ID}) {
 /call Cast "Complete Healing" gem1
}

If (${Target.ID}) does not evaluate to zero (0), then cast the spell Complete Healing on current target.

/if (${Target.ID}) {
 /echo I have a target
} else {
 /echo No target
}

If (${Target.ID}) does not evaluate to zero (0), then write "I have a target", otherwise write "No target."

/if (${Target.CleanName.Equal[Banker Denton]}) {
 /echo Banker targeted
} else /if (${Target.CleanName.Equal[Ward Toft]}) {
 /echo Ward targeted
} else {
 /echo Banker or Ward not targeted
}

If your current target is Banker Denton, then write "Banker targeted", else If your current target is Ward Toft, write "Ward targeted", otherwise write "Banker or Ward not targeted."

See also