MQ2DataVars
MQ2DataVars
MQ2Data was designed so that accessing information could be done utilizing a uniform system. User variables are utilized as MQ2Data Top-Level Objects.
About Types
User variables can be declared as any MQ2DataVars type, however there is no reason to create a variable that is an independent type such as the macroquest type, although it will work.
Scopes
There are three scopes used by macros.
global Variables of global scope ALWAYS exist until they are deleted or macroquest ends
outer Variables of outer scope exist while a macro is running
local (default) Variables of local scope only exist while within a macro function or "Sub"
Commands specific to user defined variables
/declare varname|varname[array extents] [type] [local|global|outer] [defaultvalue] Creates a variable within a particular scope and of a particular type. The parameters must be given in order, but any after varname may be skipped to use the default.
The default type is string The default scope is local The default value is nothing (empty string, or 0) These variables can be of any type that exist in MQ2DataVars. The variable will then have access to the members of that type.
Examples
/declare MyVar int outer
Creates an int variable named MyVar that exists while the macro is running
/declare MyVar local
Creates a string variable named MyVar that exists within the Sub it was created in
/declare MyTimer timer outer 3000
Creates a timer named MyTime that is set to 3000 at creation and exists while the macro is running
Arrays
To create an array, attach brackets to the end of the variable name and place in it the number of elements per dimension.
Array Examples
MyArray[10] int Creates a single-dimension local array of int with 10 elements (1-10) all 0
MyArray[10,10] int outer 5 Creates a 2-dimensional 10x10 elements(1-10,1-10) int array of scope outer with all values of 5
MyArray[4,5,6] string outer UNDEFINED-ARRAY-ELEMENT Creates a 3-dimensional array with 4x5x6 elements (1-4,1-5, 1-6) with UNDEFINED-ARRAY-ELEMENT in each location There is no limit to the number of dimensions or the number of elements in each dimension, but use your own good judgement.
Note: You cannot make an array of timers.
/deletevar varname [*|global]
Deletes the variable varname. Using * global will delete all global variables.
/varset varname [newvalue]
Sets a variable directly to a new value. Keep in mind that the type itself may reject this value depending on what you give it. To clear the value of the variable, you may omit the new value.
Examples
/varset MyString ${MyString}stuff
concatenate a string variable
/varset MyString stuff${MyString}
inserts stuff at the front of ${MyString}
/varset MyInt 123
Sets MyInt to 123
/varset MyTimer 123s
Sets MyTimer to 123 seconds
/varset MyFloat 1.23
Sets MyFloat to 1.23
/varset MyIntArray[n] 123
Sets array element n to 123
/varcalc varname formula
Sets a variable directly to the numeric result of a calculation. Keep in mind that the type itself may reject this value depending on what you give it. This will NOT work on strings!
Examples
/varcalc MyInt 1+2*2+1
/varcalc MyInt 1+(2*2)+1
/varcalc NumBuffSlots ${Me.FreeBuffSlots}+${Me.CountBuffs}
/vardata varname newMQ2Datavalue
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 most useful for when you want to keep the result of something instead of trying to make the variable accept a string with
/varset.
Example
/vardata MyFloat Math.Calc[${Me.X}+${Me.Y}]
Parsing
It is important to note that parsing of variables is performed from the inside to the outside, so any ${} inside your MQ2Data usage get evaluated before continuing.
Example
${MyString${MyVar}}
The parser first evaluates ${MyVar}. If MyVar's value is 1, this is then ${MyString1}. ${MyString1} is then evaluated, giving the value of whatever MyString1 is. ${${MyString}} will get the value of a MQ2Data query stored in MyString. This could be Me.Buff[1], or a variable name, or anything that is valid inside ${}. There is no limit to this recursion.
${${${${${${${${${${MyString}}}}}}}}}} will evaluate inside to outside until there is nothing left to evaluate.
This is also true for arrays: ${MyArray[${MyInt}]} has no problems.
Retrieved from "http://www.macroquest2.com/wiki/index.php/MQ2DataVars"