| WOW Gold Home -->Syntax overview |
There can be an awful lot of confusion around how macro options work, so I will take this early opportunity to break down the general concepts behind them. I will be providing some real-world examples using actual options. Don't worry too much if you don't understand what they mean. All options will be covered in detail later on.
General options syntax
All slash commands basically work the same way. You have a command, and a set of parameters. The parameters depend on the command, and some commands don't take any. Here are a few examples:
Macro options allow you to choose a set of parameters based on a number of criteria. At the highest level, you have a set of criteria/parameter groups separated by semicolons. The criteria consist of zero or more sets of conditions. Each condition set is enclosed with square brackets. Here is an illustration of this basic syntax.
/command [conditions] [more conditions]
parameters; [conditions] parameters ...
As you saw in the basic examples above, the command is evaluated from left to right. As soon as it finds a set of conditions that are true, it runs the command with the corresponding parameters. If there are no conditions in a clause, it will always be true. In fact, you can imagine a single-spell /cast command as a macro option with one clause that has no conditions. When the command does not have any conditions that are true, it will not execute at all.
Condition syntax
Each set of conditions is a simple comma-separated list. They can appear in any order, though [target=] is always taken into account first, before any of the conditionals. Think of the comma as an "and." A condition like [help, nodead, target=focus] means "My focus is friendly AND not dead."
Notice: Conditions are case-sensitive. If you use [Help] instead of [help], the macro will generate an error. However, this does not necessarily include the condition's parameters (described below). Still, it's usually better to consistently capitalize as things appear. Write spells and items just like you see in their tooltips. Follow the examples in this guide precisely.
Conditions themselves have a few building blocks. First off, as you just saw with "nodead", you can put "no" in front of a condition to mean the opposite. Notice that [nohelp] does not mean the same thing as [harm]. [harm] and [help] both return true only if there is a target to begin with. Furthermore, there are some targets that can neither be helped nor harmed (unflagged players of the other faction, non-combat pets, escort quests, etc.).
Some conditions also take their own sets of parameters. For example, [stance] by itself means "In any stance" (useful for every class with stances except Warriors since they are always in a stance). However, you can also specify one or more particular stances to check. The set of parameters begins with a colon (:) and each parameter is separated with a slash (/) that means "or." Here's a generic illustration of the syntax of a single condition where everything inside angle brackets (<>) is optional.
[<no>condition<:parameter</parameter</parameter<...>>>>] Here's a simple example that uses Shield Bash in Defensive or Battle Stance, but switches into Defensive Stance if you're in Berserker:
/cast [stance:1/2] Shield Bash; Defensive Stance
Note: "no" applies to the whole condition and all of its parameters. This means that [nostance:1/2] would mean "anything but stances 1 or 2"
Empty parameters
One source of confusion comes in dealing with parameterless commands. A very common error when writing macros is to add an extra semicolon to the end, but this creates some unexpected bugs. Take the following macro:
/petattack [target=focus, harm];
To the uninitiated, that looks like it'll send your pet after your focus if it's harmful, and do nothing otherwise. However, let's look at a breakdown of this macro:
/petattack [target=focus, harm] ; \________/ \__________________/ V V V | | | | | command options | | parameters (empty) | | | options (empty) | parameters (empty)
See that extra blank set of options & parameters? Remember that a blank set of options always evaluates to true, so that second empty parameter gets passed to /petattack if the first conditions are false.
Empty conditions
Sometimes you may want a command to cast on a particular target under certain circumstances but behave like normal if those conditions aren't true. In this case you will want to use an empty set of conditions which will always evaluate to true. The following macro will cast Flash of Light on the unit under your mouse. If you have no mouseover or it's hostile, the macro will behave like a plain /cast Flash of Light, casting on your target and respecting self-cast key and auto-self-cast interface option.
/cast [target=mouseover, help] [ ] Flash of Light
[target=] vs. unit parameters
Some commands accept units directly as their parameters. For example, /target party1 will target your first party member. The command /target [target=party1] while a bit more verbose has the equivalent behavior. However, in most cases the designers don't want us to be able to test conditions on one unit and then act on another, so you must use one or the other. E.g., a macro like the following will not work as expected:
/target [target=focus, dead] party1
WoW will ignore party1 because you set a unit with the [target=]. There are some specific exceptions to this rule. A few commands have "key units" that are fundamental to the command. If you use that unit in your [target=], WoW will allow you to specify another unit or will use the default unit for the command if you don't specify one. That last bit needs a concrete example:
/focus [target=focus, dead] [target=focus, noharm] target
In this case, the key unit is focus. Since we are using [target=focus], WoW will send "target" to the /focus command. We could also have left off the "target" at the end since the /focus command defaults to your target. Below is a list of all commands with key units, and their default units if any. To reiterate for clarity, the key unit is a unit you can use in [target=] that will allow you to send another unit to the command. The Default Unit is the unit that will be sent to the command if you don't provide one.