Project

Profile

Help

Macros » History » Sprint/Milestone 1

Vincent Le Goff, 12/05/2018 07:59 PM

1 1 Vincent Le Goff
h1. Macros
2
3
CocoMUD supports a system of macros as most MUD clients do, allowing to link a shortcut with an action (as a command to be sent to the server).  This document explains the creation of simple and more complex macros.
4
5
{{toc}}
6
7
h2. Basic feature
8
9
In its most simple version, a macro is a link between a keyboard shortcut and a command: for instance, if you press @Ctrl + F1@, CocoMUD may send the "look" command to the server.  In this documentation, we will see how to create a macro to link the @F1@ key with the "north" command, as some MUD clients are already configured to doing.
10
11
h2. Adding a macro
12
13
There are two ways to add a macro, and as the interface is the easiest alternative, we will see it first.
14
15
h3. Through the interface
16
17
In the menu bar, select *Game* -> *Macro*.  A dialog box should open with your list of current macros.  More likely than not, this list will be empty at first.  Click on the *Add* button.
18
19
Another dialog opens.  The cursor should be on a text entry, but you are not expected to type in it, just press the key combination.  For instance, in our example, press the @F1@ key.
20
21
When you do, "F1" should appear in the text entry.  You can try to press a lot of different keys.  For instance, press the @Ctrl@ key, hold it down and press the @I@ key, then release both keys.  You should see in the text area:
22
23
<pre>
24
Ctrl + I
25
</pre>
26
27
You can, in theory, use Shift, Ctrl or Alt in your macros.  It's not recommended to use Alt, however, since it can be linked to menu shortcuts (like @Alt + F@ to open the *file* menu).  There's not many limitations on what to use for macros.  For instance:
28
29
<pre>
30
Shift + Backspace
31
Ctrl + F12
32
Ctrl + Shift + O
33
Ctrl + PavNum8
34
</pre>
35
36
If you wish to connect a macro to a key from the numpad, you should switch it on before pressing the *Add* button, or at least, move in another area before doing so.  Otherwise, CocoMUD will associate a macro with the Numpad Lock key, which isn't often desirable.
37
38
When you have pressed the desired shortcut to associate with this macro, press Tab to go to the next area.  It's also a text area, this time for the command to be sent to the server.
39
40
So, following our example, you pressed the *Add* button, then @F1@, then Tab, you can now type "north".
41
42
If you tab again, you find a list of actions.  We will study it later, it's only necessary for more complex macros, so you can press tab again until you find the *OK* button.  Click on it to add the macro.  You should see it in the list of macros.
43
44
If you want to change the command to send to the server for a specific macro, you need to edit it (selecting it in the list of macros, and clicking the *Edit* button).  However, if you wish to change the shortcut associated with this macro, you can just select it, then press Tab.  The cursor will be in another text area, or rather, in a shortcut area, when you can press a new key to associate with this macro.  Simply do so, then navigate to *OK* to save the modifications.  If you close this dialog box without pressing *OK*, the modifications you have done (including the macros you have added) will be lost.
45
46
Back in the client's main window, press the @F1@ key.  The command is sent (silently) to the server and, if you are connected to a server that understands this command, you should receive an answer.  In my case, I get:
47
48
bq. You cannot go in that direction.
49
50
h3. Through SharpScript
51
52
You can also add a macro through SharpScript.  This is the way your macros added through the interface are stored, incidentally.  A file, named "config.set", is created in your world settings, containing your macros, aliases and triggers, as well as additional configuration.
53
54
To create a macro, you should use the @#macro@ action.  It takes two arguments:
55
56
* The shortcut to associate with this macro.
57
* The command to send to the server.
58
59
In our example, we could have created our macro using the following SharpScript instruction:
60
61
<pre>
62
#macro F1 north
63
</pre>
64
65
You can actually paste this instruction right in your client's main window and press RETURN, just as if to send a command.  CocoMUD sees that the command beings with a single sharp symbol and sends it to the SharpScript interpreter.  If you add a macro in this way (assuming you made no mistake), it will be visible instantly in the *Game* -> *Macro* menu.
66
67
If one of the parameter is too long, don't forget to place it between braces:
68
69
<pre>
70
#macro {Ctrl + Shift + O} {say that's a rather long line of text.}
71
</pre>
72
73
Braces are necessary when your parameter contains spaces.  You can put them even if your parameter doesn't contain spaces, the SharpScript engine will not mind.
74
75
h2. Editing a macro
76
77
We saw how to edit a macro in the previous section.  There's nothing really complicated about it, actually.  Just remember that, if you only with to change a shortcut associated with a macro, you can simply select it in the list of macros (in the *Game* -> *Macro* menu) and press Tab, then press your new combination of keys to associate with this macro.  If you wish to change the text to send to the server, however, you should select the macro and press the *Edit* button.  The dialog is the same as described above to add a new macro.
78
79
h2. Removing a macro
80
81
You can easily remove a macro.  In the interface (menu bar -> *Game* -> *Macro*), select the macro you wish to remove and click the *Remove* button.  You will be asked for confirmation.  Don't forget to exit the dialog box by clicking on *OK*, otherwise the macro won't be removed.
82
83
h2. More complex macros
84
85
Macros often connect a keyboard shortcut to a command being sent to the server.  But they can actually connect a keyboard shortcut with more complex actions, like playing a sound, displaying a message or a variable, displaying a channel or more.  The interest is not always obvious at first glance.  The example of more complex macros can be found in some configurations, when the world provides audio prompting, for instance.
86
87
The general idea of audio prompting is that the line of prompt (where you can find health points and movement points and that appears at each command, or almost) is hidden.  It is captured by a trigger.  The information is stored in variables.  That's beyond the scope of this document to explain how, but the important point is, you can configure a macro to display this variable.  For instance, if you press @Ctrl + H@, you should get the health points (captured by the trigger).
88
89
We have used the second text area to send commands to the server.  The truth is, you can also type SharpScript instructions in this area.  But as writing SharpScript can be a bit technical, you can also use the SharpScript editor.  It is not as complicated as it sounds: when you add or edit a macro, simply leave the second text area blank.  Tab to the list of actions and select one.  For instance, select "Display a message and send it to the screen reader".  Click on the *Add action* button.  You will be prompted for additional information (in this case, what message to display and how to display it).  When you're done, click *OK*.  In the second text area will be your SharpScript instruction.  You don't need it, it's just a landmark.  Click on the *OK* button several times to exit the dialog by saving your modifications.