Subroutines
Subroutines
Every macro has a Sub Main that defines the macro's entry point. Sub Main accepts parameters if desired.
Sub Main . code . /return
Additional Subs can be defined and used with /call. /return will return to the statement after the /call.
All subroutines and Sub Main accept passed in parameters. Some information you need to remember is: You do not have to define parameters for a sub Parameters passed to a Sub without defined parameters will default to Param0, Param1, ... Paramn Default parameters are of type string If you define the parameters of a Sub, the parameters can be of any data type that exists in MQ2DataVars If the type of a defined parameter is not given, it will default to string When you define the parameters, you may use the parameter names as variables in the sub If parameters are undefined, you would use Param0, Param1,...Paramn as the variable names Sub Main(int MyParam1, MyParam2, float MyParam3) /if (${Defined[MyVar2]}) /goto

oThis /call MySub ${var1} ${var3} /echo This value was returned from MySub: ${Macro.Return} /return
Sub without defined parameters
Sub MySub /if (${Defined[Param0]}) /goto

oThis . execute this code when /call MySub is executed. Parameters are not necessary. . /return [value|${varname}]
Sub with defined parameters
Sub MySub(int MyParam0, bool MyParam1, MyParam2) . execute this code when /call MySub is executed. . /return [value|${varname}] The above Sub has 3 Parameters, MyParam0 is an int type, MyParam1 is a boolean type , and MyParam2 is a string type.
Special subroutines (Chat, Timers, and Custom) starting with Event_ are used in conjunction with the command /doevents
Chat Events
Sub Event_Chat[(ChatType,Sender,ChatText)]
ChatType : Channel of message (tell, group, say) Sender : Name of the person who sent the message ChatText : Text they sent
Example
Sub Event_Chat[(ChatType,Sender,ChatText)] . This code is executed when /doevents finds(queues) text in the channel defined by #chat "channel" . /return [value|${varname}]
Timer Events
Sub Event_Timer[(Timer,OriginalValue)] Timer: Timer that fired OriginalValue : Value timer was originally set to Example
Sub Event_Timer[(Timer,OriginalValue)] . This code is executed when /doevents detects(queues) any defined timer reaching 0 . /return [value|${varname}]
Retrieved from "http://www.macroquest2.com/wiki/index.php/Subroutines"