Alias » History » Sprint/Milestone 1
Vincent Le Goff, 12/05/2018 07:54 PM
1 | 1 | Vincent Le Goff | h1. Aliases in CocoMUD |
---|---|---|---|
2 | |||
3 | Aliases are a special feature of MUD clients that can be used to shorten commands. An alias is itself a command, but instead of being sent to the server as is, it is first analyzed by the client, modified and extended if necessary. Some aliases don't leave the client at all. |
||
4 | |||
5 | This document will introduce the concept of aliases and explain how to create and manage them. |
||
6 | |||
7 | {{toc}} |
||
8 | |||
9 | h2. Adding an alias |
||
10 | |||
11 | You can create an alias using the interface or through the [[#SharpScript-syntax|SharpScript syntax]]. The interface being easier at first glance, it will be explained in first. |
||
12 | |||
13 | h3. Through the dialog box |
||
14 | |||
15 | In the menu bar, select Game -> Aliases. You will find yourself in a dialog listing the current aliases for this world. Note that aliases are usually created in a world, being shared by characters. This will change in future versions. |
||
16 | |||
17 | In this dialog, you can add, edit or remove aliases. By default, the list of alias will most likely be empty, so you can select *Add* to add one. |
||
18 | |||
19 | You will then have to choose an alias name. This is the command you want to create, basically. In this example, we're going to create a "tts" alias that enables/disables the text-to-speech in the client. |
||
20 | |||
21 | Enter "tts" in this field. When you press Tab, you will be presented with a list of actions to be performed when you type this command. For instance, you may want the "rs" alias to send two commands at the MUD server: "reload" and "shoot". In this case, you would select the action named "send one or more commands to the server". |
||
22 | |||
23 | In our example, we'll select "Enable/Disable TTS", since that's what we want to do when we type "tts" in the client. Tab again and click the *Add action* button. |
||
24 | |||
25 | You will be prompted with a dialog asking you to review parameters to this action. For this action, there is none, so you can press "OK" to add the action. |
||
26 | |||
27 | The new action has been added. The cursor will be put in the list of current actions linked to this alias. You can link an alias with several actions (even with the same action several times, to play several sounds, for instance, although it might not be very useful). |
||
28 | |||
29 | The list of current actions may be a bit scary. It contains summarized information. If you have selected the "Enable/Disable TTS", it will create the action @#tts@. That's a shortcut, a notation used by the SharpScript engine, and you don't need to worry much about it, unless you want to play with the scripting system in CocoMUD. |
||
30 | |||
31 | To summarize the dialog when you add or edit an alias, you will find: |
||
32 | |||
33 | * The alias' name (a text edit). |
||
34 | * A list of actions that are currently linked with this alias. If the alias isn't linked with any action, the list won't appear. |
||
35 | * A button to edit the selected line of action. If the alias isn't linked with any action, the button won't appear. |
||
36 | * A button to remove this line of action from the alias. If the alias isn't linked with any action, the button won't appear. |
||
37 | * A list of actions that can be linked to this alias. |
||
38 | * The button to add this action. |
||
39 | |||
40 | You should get accustomed to this dialog, as it will be present for most configuration involving SharpScript. It is, in fact, the SharpScript editor that do not ask you to edit the configuration file by hand. You will find more examples in the rest of the documentation. |
||
41 | |||
42 | To save the alias, don't forget to select "OK" several times, until the dialog box is closed. |
||
43 | |||
44 | If you then type "tts" in the client, you should see (and hear): |
||
45 | |||
46 | <pre> |
||
47 | TTS off. |
||
48 | </pre> |
||
49 | |||
50 | Type it again to switch it on. The text-to-speech will be disabled or enabled using this alias. |
||
51 | |||
52 | h3. SharpScript syntax |
||
53 | |||
54 | You can also add an alias by editing your configuration file and adding it there. This solution might be preferred by some. |
||
55 | |||
56 | Open your configuration file for this world. You will find it in the "worlds" directory. Select the directory containing your world, then the "config.set" file. You can open it with a small editor like notepad. |
||
57 | |||
58 | To add an alias, use the @#alias@ action with two parameters: |
||
59 | |||
60 | * The alias' name. |
||
61 | * The alias' actions to be performed. |
||
62 | |||
63 | If you want to create a "tts" alias that will enable or disable the text-to-speech, add in your file the following line: |
||
64 | |||
65 | <pre> |
||
66 | #alias tts #tts |
||
67 | </pre> |
||
68 | |||
69 | If you have several actions, don't hesitate to describe the alias on several lines: |
||
70 | |||
71 | <pre> |
||
72 | #alias go { |
||
73 | #play sounds/go.wav |
||
74 | #say {Here we go!} |
||
75 | } |
||
76 | </pre> |
||
77 | |||
78 | For an explanation of the SharpScript syntax, refer to [[SharpScript|the section describing SharpScript]]. |
||
79 | |||
80 | h2. Editing an alias |
||
81 | |||
82 | At any time, whether you have created the alias in the dialog box or in the configuration file, you can edit it. If you have created it in the configuration file, you can modify it through the interface, and vice versa. |
||
83 | |||
84 | Remember that the configuration is loaded when you select the world, which will most likely happen when you open the software. If you modify the configuration file, restart the software to take it into account. |
||
85 | |||
86 | h2. Removing an alias |
||
87 | |||
88 | You can remove an alias through the dialog box or by editing the configuration file. If you do it through the dialog box, remember the changes will be lost if you close the dialog but do not use the "OK" button. |
||
89 | |||
90 | h2. Aliases with variables |
||
91 | |||
92 | CocoMUD provides a system of variables. They can be used anywhere in your script or in any feature using the SharpScript engine (aliases, macros, triggers...). |
||
93 | |||
94 | Variables can be more than useful for aliases to create shortcut commands with unknown parameters. For instance: |
||
95 | |||
96 | bq. I want to create an alias that begins by @=@. Everything after the @=@ sign should be sent to the server using the @say@ command. If I type @=hello !@ in the client, then it should send @say hello !@ to the MUD. |
||
97 | |||
98 | For this case study, we will use variables. The alias begins by an equal sign (@=@), but we don't know what's after that. How to handle that context? We will use the @*@ sign in our alias name, which means "about everything, as long as necessary". |
||
99 | |||
100 | So if we enter @=*@ as an alias name, CocoMUD will understand it as meaning "everything starting with an equal sign". |
||
101 | |||
102 | But we don't only need for the alias to be activated. We need for it to send a command with what has been entered after the equal sign. Here is the process step by step, explained below: |
||
103 | |||
104 | * In the menu bar, select *game* then *aliases*. |
||
105 | * Click the *add* button to add a new alias. |
||
106 | * In the alias field, enter @=*@ (an equal sign and the asterisk sign). |
||
107 | * Tab to move to the list of actions that can be linked to this alias. |
||
108 | * Select "send one ore more commands to the server", tab and click the *add action* button. |
||
109 | * You'll be asked to configure this action. Tab until you hear "Commands to be sent to the server". In this field, type @say $1@ (the @$1@ will be explained below). |
||
110 | * Select *OK*. The action has been linked, and you should see it in this field: |
||
111 | <pre> |
||
112 | #send {say $1} |
||
113 | </pre> |
||
114 | What it means will be detailed below. |
||
115 | * Tab until you find the *OK* button and click on it. You will find yourself in the list of aliases, press *OK* again. |
||
116 | |||
117 | If you type in the client: |
||
118 | |||
119 | <pre> |
||
120 | =hello ! |
||
121 | </pre> |
||
122 | |||
123 | The alias will send "say hello !" to the server. |
||
124 | |||
125 | What happens is pretty simple: |
||
126 | |||
127 | * You enter "=something". |
||
128 | * CocoMUD identifies a matching alias. |
||
129 | * The "something" part (after the equal sign) will be captured and put in a variable, called @$1@. |
||
130 | * When you send "say $1" to the server, CocoMUD replaces it @$1@ with the "something" part. |
||
131 | |||
132 | The variable is called @$1@ because you can create a lot of variables. If you enter the alias: |
||
133 | |||
134 | <pre> |
||
135 | -*+* |
||
136 | </pre> |
||
137 | |||
138 | You will be able to send: |
||
139 | |||
140 | <pre> |
||
141 | remove $1 |
||
142 | wear $2 |
||
143 | </pre> |
||
144 | |||
145 | And then type: |
||
146 | |||
147 | <pre> |
||
148 | -cloak+armor |
||
149 | </pre> |
||
150 | |||
151 | Variables in SharpScript are described more completely in [[SharpScript|the section describing SharpScript]]. |