# /vardata

## Syntax

**/vardata varname** ***newMQ2Datavalue***

## Description

Sets a variable directly to the end result of a MQ2Data string.\
\*To use this, **do not** put ${} around the outer data to parse.

* This is more efficient than using */varset* as it skips a step
  * */varset* first converts the MQ2Data to text, and then back to MQ2Data
  * */vardata* converts directly through MQ2Data

## Examples

```
/vardata MyFloat Math.Calc[${Me.X}+${Me.Y}]

/vardata M_Assist Param0

| using /vardata with non-basic data types

/declare x int local
/declare xSpawn spawn local
/for x 1 to ${SpawnCount[pc]}
   /vardata xSpawn NearestSpawn[${x},pc]
   /echo ID:${xSpawn.ID} NAME:${xSpawn.Name}
/next x
```

## See Also

* [MQ2Data](https://github.com/macroquest/docs/blob/master/documentation/mqdata.md)
* [/varset](/macroquest/commands/macro-commands/varset.md)
* [/varcalc](/macroquest/commands/macro-commands/varcalc.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/vardata.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.
