• IS THIS SITE UGLY? Click "RG3" at the very bottom-left of this page to change it. To dismiss this notice, click the X --->

Guide - Maskoi's Guide to Writng Macros - Introduction

Maskoi

So old and salty he grew scales
Moderator
Joined
Sep 28, 2005
Likes
666
RedCents
68,160¢
#1
Introduction

This guide is my approach to writing macros. I hope it will help get some people pointed in the right direction if they are interested in writing macros.

Writing a guide is not an easy task. I don't think a marathon post is the best way to approach it. It would miss a lot of stuff because I would have to skip many things to keep it readable. I am going to treat this guide as a blog and add one section at a time. I will try to post some thing at least twice a week. Hopefully over the next month or two something useful will emerge for those trying to learn about writing macros.

Programming vs Coding


Macroquest2 (MQ2) macros are written in a scripting language. I will be using the terms like writing or coding a macro instead of programming. Macroquest2 itself is a program. The difference being the executable file with its dynamic library files (DLLs) or plugins are programed in C++ and then compiled to run on Microsoft Windows. Macros are written scripts or instructions the MacroQuest2.exe file interprets to run the commands you want to do.

Programming and coding/scripting have a lot in common specially with MacroQuest2. MacroQuest2 was written by C programmers so the scripting language follows a lot of the same syntax. The difference again being the macro is not compiled but run and interpreted or parsed by the MQ2 program and its plugins.

I personally try to follow some programming best practices for coding my macros that make them more readable to other coders. The main ones are indentation and simplicity.

Indentation


Here is a random chunk of code from KissAssist. It is 2 nested for next/ loops. Don't worry about what it means I am just showing you the differences in readability without and with indentations.
Without indentation. This is lazy and sloppy. People will not be inclined to help you with your macro if they have reformat or spend an hour trying to figure out the structure of your code.

Rich (BB code):
/for j 1 to ${MobCount}
/varset CheckSpawnID ${NearestSpawn[${j},npc targetable los radius ${AERadius} zradius 50 noalert 3].ID}
/for i 1 to ${XSlotTotal}
/if (${Me.XTarget[${i}].TargetType.Equal[Auto Hater]} && ${Me.XTarget[${i}].ID}) {
/if (${CheckSpawnID}==${Me.XTarget[${i}].ID}) {
/varcalc ArrayCount ${ArrayCount}+1
}
}
/next i
/if (${ArrayCount}==0) {
/varcalc MobCountTemp ${MobCountTemp}-1
/if (${DebugCombat}) /echo \atDEBUGCOMBAT AECheck MobCountTemp:${MobCountTemp} after xtarget spawn check \agLine#: ${Macro.CurLine}
}
/varset ArrayCount 0
/next j
With indentation. The code for each for/next loop is indented so you know where the loops start and what code is inside each loop. Once again just an example. You not expected to understand this code but which example would you rather try and learn from?

Rich (BB code):
/for j 1 to ${MobCount}
    /varset CheckSpawnID ${NearestSpawn[${j},npc targetable los radius ${AERadius} zradius 50 noalert 3].ID}
    /for i 1 to ${XSlotTotal}
        /if (${Me.XTarget[${i}].TargetType.Equal[Auto Hater]} && ${Me.XTarget[${i}].ID}) {
            /if (${CheckSpawnID}==${Me.XTarget[${i}].ID}) {
                /varcalc ArrayCount ${ArrayCount}+1
            }
        }
    /next i
    /if (${ArrayCount}==0) {
       /varcalc MobCountTemp ${MobCountTemp}-1 
       /if (${DebugCombat}) /echo \atDEBUGCOMBAT AECheck MobCountTemp:${MobCountTemp} after xtarget spawn check \agLine#: ${Macro.CurLine}
    }
    /varset ArrayCount 0
/next j
Simplicity

This comes with experience. The way I explain it is why do something in 5 lines of code when you can do it in 2. As a beginner, you will be writing a lot of unnecessary code to accomplish what you want your macro to do. When you become more experienced you will learn better and more efficient ways of coding the same thing. You will be writing a lot of code and it is necessary to learn so don't beat yourself up on this but try to keep it in mind.

Talking about becoming more experienced in macro writing I am going to mention fluency. This is something most macro guides don't ever mention. If you enjoy writing macros you should strive for Fluency in the MQ2 macro language. Fluency is when you no longer think of what code you have to write you just automatically know it.
In English to Spanish you need to think what is Green. Its Verde.
Fluency is when you see green and its Verde automatically no thought in involved.

Same thing with writing macros. I want to let the user know he has acquired a target in the MQ2 window. How do I do that? Check other macro, where is the bookmark I saved, ok its /echo.
Fluency is just typing /echo You have acquired a target. ${Target.CleanName}

Fluency comes with experience and work. Try to memorize and learn the most common and basic commands you are using in your macros.

I will try to add to this guide every couple of days. My goal is to keep short and interesting.

Please comment only on the article in the post. If there is something you don't understand I will try and clarify or expand on it and add to the current article of the guide.

Thanks for reading
 
Last edited:
Joined
Apr 9, 2018
Likes
83
RedCents
446¢
#2
Just made a posted and made the indentation mistake. I did not notice it was not keeping formate after copy/paste. Tried to edit and stumble into that toggle bb code button but can't seem to make it stick. After saving everything goes to the right. How to you get it to keep format?
 
Joined
Dec 29, 2017
Likes
984
RedCents
4,170¢
#3
you wrap it in code blocks. a code block has [ open and ] close block with the word code inbetween. After you've pasted the code you use the /code to end it which is also enclosed in square brackets.
Code:
Put code 
    in here
    then close the code block
1552274253021.png
 
Top