My first macro

dulak

Vagoo!
Joined
Jul 9, 2006
Messages
1,460
Reaction score
4
Points
38
I know there are countless language learning macros but I figured for a beginner it'd be the easiest to code so here is my first macro.
Code:
sub main
:loop
/gsay nothing new
/goto :loop
/return


I know it's uber simple but at least I tried lol


Edit: Added the code brackets and added the good coding practice as was suggested.
 
Last edited:
Teach good coding habits...even if the loop never breaks, always have a /return statement at the end of each sub.
 
Is there a reason for that?

I used to do that, but have begun cutting useless lines out of my macros. 100% redundant checks, messed up TLO checks, such like that.
 
Most of this stuff you're talking about I have no idea what it is. I quite literally know nothing about coding and am actually surprised that this one worked. What does a "return" statement do and how would it help the macro?
 
Like I said, it's a good coding habit...especially for someone just starting out.

As for being necessary...well, any subroutine will need a return of SOME sort, or the macro will just keep reading lines and end up in the next sub, causing the macro to end with an error. In the very strictest sense, yes, having a return at the end IS necessary. For example:

Code:
sub main
:loop
/call exone
/call extwo
/goto :loop
/return ||Not strictly necessary, since the :loop will never stop unless you end the macro.

sub exone
/if (${Condition}) /return
/echo OMGZORZ
/return

sub extwo
/if (${Condition}) {
   /echo OMG
   /return
} else {
  /echo NOOO
  /return
}

In "exone", you have extra code after your ${Condition}, making that return necessary (also, if that condition is false, you'd need the extra /return). In "extwo", having a return at the end isn't necessary because no matter what ${Condition} returns, you will return. That said, since optimization is your goal, you could look at it this way: Since the "/return" will happen no matter what, you've got an extra line in there. If you pulled the return out, you'd remove one line.

Code:
sub extwo
/if (${Condition}) {
   /echo OMG
} else {
  /echo NOO
}
/return

If you're really looking to optimize, though, then with these one-line commands it'd be easier to just remove the {}:
Code:
sub extwo
/if (${Condition}) /echo OMG
/if (!${Condition}) /echo NOO
/return
 
@dulak

Macros give you an ability to create a "sub", short for subroutines. These pieces of code are lines that you might repeat often in many places, or for other uses. For example, "sub main", which you have in your macro, is what MQ2 activates when it wants to start the macro.

This is what I would add:
Code:
sub main
:loop
/gsay nothing new
/goto :loop
[color=red]/return[/color]

The reasons are two:

1) When you start making more complicated macros, it separates the end of one "sub" from the next, allowing you to easily see where one bit of code ends.

2) What "/return" does is exactly what it says it does -- it "returns" to the point in the code where that "sub" was activated. For example:

Code:
sub main
/echo Start
/call next
/echo Finish
/return

sub next
/echo Middle
/return

That will echo Start, Middle, Finish in that order. What happens is that MQ2 reads the line telling it to echo Start, and does that. Then it reads the "/call" command, which tells it to find "sub next". Once it does that, it does /echo Middle. Once it does that, it hits the "/return" command, which tells MQ2 to go back to "/call next", and keep going from there. So what happens is that it goes back to "/call next", and reads the next line, which is "/echo Finish". After it does that, it hits a "/return", which (in sub main) tells MQ2 that the program is done.

--Please, ask any questions you might have. I'll try to answer them as best I can...always love to help new guys get started, and I know that this can be a lot to absorb.
 
A complete guide on what does what and how it works would be nifty lol j/k I plan on writing more, just need a better understanding of what triggers what and how exactly things work.
 
Thanks, I'll give it a look and see if it can help me out some.
 
besides the wiki the manual is also very good, it has the same info for the most part asthe wiki just you can use search function for key words and scroll thru them.

IRC and asking for help is also a very good way to learn. Or pms, Shoutbox = worse possible way to get help =p
 
Have to agree, the shoutbox takes too bloody long to update. For this mac, I'd really like to get it to alternate between the available mastered languages and autostop when the character that is learning reaches max but not sure if that would be a bit difficult to do or not.
 
there already is a macro for this out there, however i dont want to discourage you from doing one your self. only way to have the macro move on when learning toon is maxed is to have them run a macro with and even to trigger a key response phrase the teacher macro is looking for. i dont know if there is a tlo for you to jump to next mastered language, but can do a math calc to add one to the language number your already speaking to move to next one in list, and then im guessing but could do a me.skill type check and have it /return to the math calc... again im very new to macros myself, but trying to help with what i know.
 
I don't know if MQ2NetBots would let you check skills on other characters, if so, you could use that.

Though, for that much hassle, I'd just set it up your learner with a macro like this:
Code:
#event max "You have become better at #*#! (100)"
#define MASTERNAME replace_this_with_master
Sub Main
:loop
/doevents
/delay 5
/goto :loop
/return

Sub Event_max
/tell MASTERNAME Maxxed.
/return

And then add a check so your master's macro went to the next language when it saw that event.
 
Last edited:
Don't forget to actually do something!

In my macro? That mac isn't supposed to do something.

It's supposed to let the master know when each language maxxes, so the master knows when to swap to the next one.
 
In my macro? That mac isn't supposed to do something.

It's supposed to let the master know when each language maxxes, so the master knows when to swap to the next one.

But it doesn't. It just loops. You never /doevents...