Project

Profile

Help

Channels » History » Sprint/Milestone 3

Vincent Le Goff, 12/15/2017 08:18 AM

1 1 Vincent Le Goff
h1. Channels in CocoMUD
2
3
CocoMUD offers an interesting feature of channels.  Channels are basically lists of messages and you can put whatever you want in them.  We often use CocoMUD channels to track game channels: when we receive a message on one of these channels (lie "public" or "ooc"), we can automatically capture this message and put it in a CocoMUD channel.  A simple key press could allow to display this channel and read all the messages in it.  This is pretty useful when you're exploring or figthing on the game, and don't have time to read all messages spoken by others, but you want to read them afterward.
4
5 3 Vincent Le Goff
We'll take this example for the rest of the documentation: an attempt to capture the context of a public channel.  This example also relates to [[Triggers|triggers]], which is barely a coincidence.
6 1 Vincent Le Goff
7
{{toc}}
8
9
h2. Creating a new channel
10
11
The first step is to create a channel, an empty list that will contain the messages we want to put in it.  Here, we'll create a channel named "public", for that's quite explicit.  Remember that channels can be used to capture any information, however.
12
13
In the CocoMUD menu bar, open *game* -> *channels*.  You find yourself in a dialog box showing current channels.  It's probable you don't have any at that point.  Go to the *add* button and click on it.  You will be asked the name of the channel.  Keep it short and explicit: here, we'll create a channel named @public@ .
14
15 3 Vincent Le Goff
We can now send information to this channel using [[Triggers|triggers]].  If you're not familiar with this feature, you might want to read the [[Triggers|documentation about triggers]] first.
16 1 Vincent Le Goff
17
h2. Feeding a channel with triggers
18
19
Okay, let's look at the two lines we may receive from the server.  If we send a message on the public channel, it would be displayed like that:
20
21
<pre>
22
[public] You say: my message to all
23
</pre>
24
25
If it's someone else who sends to this channel, we would have:
26
27
<pre>
28
[public] Somebody says: my message to all
29
</pre>
30
31
What's common and different in our two lines?
32
33
* Well, both begin with "public" between brackets, followed by a space.
34
* Then there's the author.  "you" or "somebody".  So we don't know what it will be, we could use an asterisk.
35
* Then is the word "say" after another space.  Wait!  When it's me, it display "you say", when it's somebody, it displays "somebody says".  What to do?
36
* After a colon and another space is our message.
37
38
To solve our issue between say/says, we have two options:
39
40
* Either we group both cases, writing "say*" (meaning say followed by nothing or anything).
41
* Or we could write two triggers.
42
43
Personally I would advise the latter, but I know some of you would prefer the former.  So let's work with both.
44
45
h3. One single trigger
46
47
What would our trigger look like in the end?  Ready?
48
49
<pre>
50
[public] * say*: *
51
</pre>
52
53
Three asterisks!  The first will contain the name of the one speaking.  Either "You" or the name of the player speaking on this channel.  The second variable will contain either "s" or nothing.  We shouldn't need it.  The third variable contains the message itself.
54
55
So to create this trigger through the interface:
56
57
* Open the menu bar, *Game* -> *Triggers*.
58
* Click on *Add* to create a new trigger.
59
* Enter @[public] * say*: *@ before pressing Tab.
60
* Select "Feed a channel with a message".
61
* Click on the *Add action* button.
62
* In the name of the channel to be fed, enter @public@ (this is assuming the channel exists in CocoMUD).
63
* In the message to feed to the channel, enter:
64
<pre>
65
$1: $3
66
</pre>
67
* Click on *OK* several times to close the dialog and save the trigger.
68
69
bq. What was that @$1 $3@?
70
71
@$1@ contains the name of the one speaking.  @$3@ contains the message.  So when we receive the line:
72
73
<pre>
74
[public] Jamie says: well done!
75
</pre>
76
77
Our channel will be fed with the following line:
78
79
<pre>
80
Jamie: well done!
81
</pre>
82
83
You could have done the same thing with a single line of SharpScript:
84
85
<pre>
86
#trigger {[public] * say*: *} {#feed public {$1: $3}}
87
</pre>
88
89
That's a bit harder to understand, but if you're familiar with SharpScript, that's definitely quicker.
90
91
A last word regarding this trigger: you may have noticed that we don't play a sound when receiving this trigger.  Nothing prevents you from adding another action to the trigger though.  Similarly, to do it with SharpScript, you would enter:
92
93
<pre>
94
#trigger {[public] * say*: *} {
95
    #feed public {$1: $3}
96
    #play sounds/public.wav
97
}
98
</pre>
99
100
h3. Two different triggers
101
102
As I have explained, to solve the problem of say/says, we could have created two different triggers.  That makes for a longer configuration, a little bit, but that's easier to read, in my opinion.  Sometimes it will not be possible to do otherwise, depending on the language the MUD is in.
103
104
Our two triggers would be:
105
106
<pre>
107
[public] You say: *
108
[public] * says: *
109
</pre>
110
111
I don't know about you, but I find it much easier to read.  Our first trigger only fires when we send a message on this channel (perhaps we could say that we won't play a sound in this case) and the second one will fire when it's somebody else who's speaking.  I'll give you the SharpScript instructions to create these triggers, but as usual, you could do the same through the interface:
112
113
<pre>
114
#trigger {[public] You say: *} {#feed public {You: $1}}
115
#trigger {[public] * says: *} {
116
    #feed public {$1: $2}
117
    #play sounds/public.wav
118
}
119
</pre>
120
121
What you'll choose is entirely up to you and the context, pick whatever feels more comfortable.
122
123
h2. Bind a channel to a macro
124
125 2 Vincent Le Goff
Feeding a channel is certainly useful, but displaying it is even better.  Most often, you will bind a macro to open a specific channel.  It's pretty easy to do.
126
127
Start by creating a macro as usual.  In the interface:
128
129
* Open the menu bar *Game* -> *Macro*.
130
* Click on *Add* to add a new macro.
131
* Press the key combination you want to associate with this macro.  For instance, *CTRL + P*.
132
* Tab twice to find the list of possible actions.  You should find in the list the "create or display a channel" function.  Select it.
133
* Tab once to add the action.  You will be asked the channel name.  You will enter @public@ here, in this case.
134
* Leave the dialogs by pressing *OK* multiple times to quit and save.  Then you can press CTRL + P: the public channel should open.  Magic!
135
136 1 Vincent Le Goff
h2. Remove a channel
137 2 Vincent Le Goff
138
Removing a channel is done through the same interface:
139
140
* In the menu bar, select *Game* -> *Channels*.
141
* Tab until you find the *Remove* button.  You will then be presented with a list of existing channels.  Select one and tab again to remove it.  If you press *OK*, the channel will be entirely removed and will not appear in your channels the next time you connect to this world.
142
143
Keep in mind, however, that triggers can still try to feed this channel.  This will fail, since the channel doesn't exist, but you will have to remove the trigger manually, as it could do other things as well.