# /if

## Syntax

**/if (** ***formula*** **) {**

***commands***

**} \[ else \[/if (*****formula*****)] { ]**

**...**

**}**

## 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 strings comparisons into

  numeric operations (eg. Using .Equal or .NotEqual).
* You may 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"

## Examples

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

/if (${Target.ID}) {
 /echo I have a target
} else {
 /echo 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
}
```

[Return to Slash Commands](/macroquest/commands/slash-commands.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://macroquest.gitbook.io/macroquest/commands/macro-commands/if.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
