Programming 101
I'm not responsible for these videos--they are from lynda.com--but them might be helpful for people learning to write macros.
What is programming?
What is a programming language?
Writing source code.
Hello World Macro.
Macro
Writing Environment
Notepad++ is a good development environment to use instead of notepad. It can be had here: http://notepad-plus-plus.org/
Notepad++ will color code keywords and syntax to help you spot errors and just generally make your code more readable. It works with a bunch of different languages. MQ macros aren't a common language so it doesn't highlight them natively. You need to install an extension. Instructions are here: http://www.macroquest2.com/wiki/index.php/Notepadplusplus_Syntax_File
Alternatively, you can click the "Macro Editor" link in our toolbar at the top of this page for a so-so macro editor for when you don't have notepad++ available.
Writing pseudo code.
Programming style.
Introduction to variables and data types.
This one gets a little bit specific to JavaScript, but the general ideas of how variables work is what's of value to you.
MacroQuest 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
Working with arrays.
Macroquest 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.
Functions
MQ function example
Macro
Building with the if statement
Working with complex conditions
Setting comparison operators
Using the switch statement
Introduction to iteration (loops)
Writing a while statement
Creating a for loop
Last edited by Maudigan on Sun Aug 18, 2013 12:21 pm; edited 1 time in total
Sat Aug 10, 2013 3:57 pm
Project Lead
EXCELLENT Tutorial
THANK YOU VERY MUCH!!!
This is exactly the kind of tutorial that a person who learns best from the show me method will excel.
If you have most please post them. I've learned more about coding in the hour then all the reading I've done over the last couple days.
_________________
Thxz Playfair {aka Darren}
Sat Aug 10, 2013 11:35 pm