# Macro Reference

## Introduction

The use of macros is what really makes MacroQuest2 extremely powerful. Additional in-game functionality like [the map](/macroquest/plugins/core-plugins/mq2map.md), cross-zone targeting, enhanced [/who](/macroquest/commands/slash-commands/who.md), custom binds, [the HUD](/macroquest/plugins/core-plugins/mq2hud.md) and [plugins](https://github.com/macroquest/docs/blob/master/documentation/macroquest-plugins.md) are useful, but macroing is what **Macro**Quest is all about.

See [here](https://github.com/macroquest/docs/blob/master/documentation/macroquest-macros.md) for some introductory information about macros. This page is concerned primarily with all the relevant information required to create your own macros.

## Macro Fundamentals

The MQ2 scripting language primarily involves the use of [Slash Commands](/macroquest/commands/slash-commands.md) (/commands), [variables](https://github.com/macroquest/docs/blob/master/documentation/mqdatavars.md), [Top-Level Objects](/macroquest/data-types-and-top-level-objects/top-level-objects.md) and some [Flow Control](/macroquest/documentation/flow-control.md) to help the macro along.

Accessing and manipulating data can be done with:

* [Variables](https://github.com/macroquest/docs/blob/master/documentation/mqdatavars.md) (MQ2DataVars)
* [MQ2Data](https://github.com/macroquest/docs/blob/master/documentation/mqdata.md)
  * [Top-Level Objects](/macroquest/data-types-and-top-level-objects/top-level-objects.md)
  * [Data Types](/macroquest/data-types-and-top-level-objects/data-types.md)
* [Slash Commands](/macroquest/commands/slash-commands.md)

Things that can be added to the macro file:

* [Comments](/macroquest/documentation/comments.md)
* [Pound Commands](/macroquest/commands/macro-commands/macro-directives.md)
  * [Custom Events](/macroquest/macros/macros/custom-events.md)

Controlling macro execution is done with:

* [Flow Control](/macroquest/documentation/flow-control.md)
  * [Operators](/macroquest/documentation/operators.md)
* [Subroutines and Functions](/macroquest/documentation/subroutines-and-functions.md)

## Include Files

An effective way to store subroutines which are used in multiple macros is by using include files. Include files hold code just like macros, but do not have a Main subroutine. To use an include file, add "#include FileNameHere" in your macro. Include files can be any file type that works with plain text, such as .txt or .ini, but .inc is the most common file type.

## Macro Tips

* Sometimes you find a macro, and it's ALMOST what you need it for. In those cases, just edit the macro for your use.

  Take a look at this tutorial: [Editing Existing Macros](/macroquest/documentation/editing-existing-macros.md)
* Be patient and expect to fail a few times. If your macro involved killing stuff, expect to die a few times to

  perfect your macro.
* Remember to check your syntax. Most of the common problems people run into are becuase they haven't closed their

  {}'s, \[]'s and ()'s properly. If you have to, start at the end of the troublesome section and start matching up

  the {}'s, \[]'s and ()'s by hand. It can really help sometimes to just print the macro and start crossing them out.
* For people using Utraedit, here is an addition you can make to your [UltraEdit Syntax File](https://github.com/macroquest/docs/tree/abfc239f4d668ae116ab48141e49bbff82337715/other-applications/ultraedit-syntax-file.md)

  that will give you some syntax highlighting and reformatting.


---

# 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/documentation/macro-reference.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.
