MQ2DataVars Reference: Usage, Examples, etc

General announcements relating to the modularized MacroQuest2 system.

Moderator: MacroQuest Developers

Lax
We're not worthy!
We're not worthy!
Posts: 3524
Joined: Thu Oct 17, 2002 1:01 pm
Location: ISBoxer
Contact:

MQ2DataVars Reference: Usage, Examples, etc

Post by Lax » Sun Apr 25, 2004 9:58 pm

Overview
MQ2Data was designed so that variables could also very easily use the same system. The way
MQ2DataVars works overall is to use variables as MQ2Data Top-Level Objects. Instead of
@Param1, you would use ${Param1} to access the variable. Each variable has a type, and in
this case Param1 is a string so you could use any member of the 'string' type directly from
the variable. So instead of ${String[@Param1].Length} to determine the length of the
parameter, you simply ${Param1.Length}.

About Types
Each MQ2Data type allows variables of that type to be created. Some types will be less useful
than others. For example, there is no reason to create a variable that is a "careless" type,
such as the "macroquest" type, although it will work.

The way each type handles data given is specific to that type. For the most part, the type of
data you would normally store in your macro before MQ2DataVars works exactly the same.

Note that /for loops REQUIRE an "int" type

Sub Parameters - woops how did this get left out of the MQ2DataVars reference? added 4-30-2004
Sub declarations can now be declared with each parameter as a specified type. To do this, you must type and name each parameter like so:
Sub MySub(string Name,int Count)

If any parameter is not given a type, the type defaults to string.
Sub MySub(Name, int Count)

Parameters not declared in the Sub declaration are strings. For example..

Code: Select all

/call MySub Bill 10 one two three four
.
.
.
Sub MySub(string Name, int Count)
/return
In this example, four extra parameters are given. The parameter naming has not changed, so default parameter names are still Param0, Param1, Param2, and so on. The four extra parameters would be Param2, Param3, Param4, Param5, and they would all be strings.

Scopes
There are now three scopes used by macros. The scope will still default to "local".

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 (this is the OLD "global")
local - Variables of local scope exist within a macro function or "Sub"

Commands
/declare
Usage: /declare <varname|varname[array extents]> [type] [global|outer|local] [default value]
Declare creates a variable within a particular scope. The parameters must be given in order,
but any after name may be skipped to use the default. The default type is "string". The
default scope is "local". The default for default value is nothing (empty string, or 0).
You cannot declare a variable of type "array". To create an array, attach brackets to the
end of the variable name and place in it the number of elements per dimension. Example:
MyArray[10] creates a single-dimension array with 10 elements (1-10). MyArray[10,10] creates
a 2-dimensional array with 10x10 elements (1-10,1-10). MyArray[4,5,6] creates a 3-dimensional
array with 4x5x6 elements (1-4,1-5,1-6). There is no limit to the number of dimensions or the
number of elements in each dimension, but use your own good judgement ;)
Note that you cannot make an array of timers.

Example usage:
string in local scope: /declare MyVar
string in local scope: /declare MyVar string
string in local scope: /declare MyVar string local
int in local scope: /declare MyVar int
int in outer scope: /declare MyVar int outer
array of int in local scope: /declare MyVar[10] int
timer in local scope: /declare MyVar timer
timer in outer scope: /declare MyVar timer outer
float in local scope: /declare MyVar float
float in global scope: /declare MyVar float global
string in local scope with value UNDEFINED-LOCAL: /declare MyVar UNDEFINED-LOCAL
array of strings in local scope with value UNDEFINED-ARRAY-ELEMENT: /declare MyVar[10] UNDEFINED-ARRAY-ELEMENT
array of strings in global scope with value UNDEFINED-ARRAY-ELEMENT: /declare MyVar[10] global UNDEFINED-ARRAY-ELEMENT
array of strings in global scope with value UNDEFINED-ARRAY-ELEMENT: /declare MyVar[10] string global UNDEFINED-ARRAY-ELEMENT

/deletevar
Usage: /deletevar <varname>
Deletes a variable.

Example usage:
/deletevar MyVar

/varset
Usage: /varset <varname> [new value]
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.

Example usage:
concatenate a string: /varset MyString ${MyString}stuff
insert into a string: /varset MyString stuff${MyString}
/varset MyInt 123
/varset MyTimer 123s
/varset MyFloat 1.23
set an array element: /varset MyIntArray[10] 123

/varcalc
Usage: /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!

Example usage:
/varcalc MyInt 1+2*2+1
/varcalc MyInt 1+(2*2)+1

/vardata
Usage: /vardata <varname> <new mq2data value>
Sets a variable directly to the end result of a MQ2Data string. To use this, do NOT put
${} around the outer data to parse. For example...
/vardata MyFloat Math.Calc[${Me.X}+${Me.Y}]

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.

Tricksy Hobbitses Use MQ2DataVars
MQ2DataVars allows plenty of crazy shit that was difficult to do with the old system. MQ2Data
parses from the inside to the outside, so any ${} inside your MQ2Data usage get evaluated before
continuing. So, ${MyString${MyVar}} first evaluates ${MyVar}. If MyVar's value is 1, this is then
${MyString1}. Then ${MyString1} is 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 works inside ${}. There is no limit to this recursion.
${${${${${${${${${${MyString}}}}}}}}}} will evaluate inside to outside until there is nothing
left to evaluate. ${MyArray[${MyInt}]} has no problems, etc.
Lax Lacks
Master of MQ2 Disaster
Purveyor of premium, EULA-safe MMORPG Multiboxing Software
* Multiboxing with ISBoxer: Quick Start Video
* EQPlayNice, WinEQ 2.0