Project

Profile

Help

Channels » History » Sprint/Milestone 1

Vincent Le Goff, 12/11/2017 02:19 PM

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
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
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
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
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
h2. Remove a channel