Elf programming example #5 |
Task: | intercept personal messages and copy them in a separate user window with an appropriate title. |
To achieve this task requires several steps:
The implementation of all those triggers is almost the same.
You simply have to create a trigger for every message that isolates the name of who's talking and what he's saying.
Let's trap the message "[Elfred] tells you 'how are you?'".
The trigger will be
[*] tells you
'*'
We also need to set the CHECK COMPLETE LINES flag.
The commands related to this trigger are
the following:
@SLocal t
@t=@ParmS(2a)
<chat @ParmS(1a),0
Note: | if you want, you can merge this trigger with the one that remaps messages to obtain a really nice result. In such case you ought to set the following flags too: REMOVE ORIGINAL LINE and LAST TRIGGER TO CHECK IF ACTIVATED. The @OUTSTR command can added as the last command. |
The second one stores in the local variable what has been told.
The third one actually invokes the user defined alias <chat with two parameters. The first one identifies the name of the talker. The second one is used to select the color (actually we'll define two different aliases that differ in the colors they use (to distinguish received from sent messages)).
The trigger used to recognise the message we send (e.g.: "You tell Elfred 'Fine thanks!'") will look like:
The trigger will be
You tell * '*'
We also need to set the CHECK COMPLETE LINES flag.
The commands related to this trigger are
the following:
@SLocal t
@t=@ParmS(2a)
<chat @ParmS(1a),1
With the same meaning of the previous trigger. The only difference is in the '1' calling the alias.
Let's define now the aliases used to (eventually) create the user window and to write the message in it. Long lines are split and the right color is used.
The alias will be activated by the pattern
chat *,0
The commands related to this alias are
the following:
@NLocal id
@id=@WOpEq(@ParmS(1t)+" (chat)")
@While @t<>""
@Skip (@Len(@t)>50)*3
@WAdd @id,@FGLightGreen+@t
@t=""
@Skip 2
@WAdd @id,@FGLightGreen+@Copy(@t,1,50)
@t=@Copy(@t,51,255)
@EndW
The function @WOpEq opens a new user window with the given title (built with the name of the person we're talking to). If a user window with the same title already exists, its id is returned without opening a new one.
The @While-@Wend loop is used to split long lines.
The alias used for sent messages is the following one. The only difference from the previous one is the color used to show the message.
The alias will be activated by the pattern
chat *,1
The commands related to this alias are
the following:
@NLocal id
@id=@WOpEq(@ParmS(1t)+" (chat)")
@While @t<>""
@Skip (@Len(@t)>50)*3
@WAdd @id,@FGGreen+@t
@t=""
@Skip 2
@WAdd @id,@FGGreen+@Copy(@t,1,50)
@t=@Copy(@t,51,255)
@EndW
Here is the necessary
programming for this task:
trigger Someone talks to me | |
trigger | [*] tells you '*' |
flags | check complete lines |
commands | @SLocal t
@t=@ParmS(2a) <chat @ParmS(1a),0 |
trigger I'm talking to someone | |
trigger | You tell * '*' |
flags | check complete lines |
commands | @SLocal t
@t=@ParmS(2a) <chat @ParmS(1a),1 |
alias Show chat messages (received) | |
pattern | chat *,0 |
flags | none |
commands | @NLocal id
@id=@WOpEq(@ParmS(1t)+" (chat)") @While @t<>"" @Skip (@Len(@t)>50)*3 @WAdd @id,@FGLightGreen+@t @t="" @Skip 2 @WAdd @id,@FGLightGreen+@Copy(@t,1,50) @t=@Copy(@t,51,255) @EndW |
alias Show chat messages (sent) | |
pattern | chat *,1 |
flags | none |
commands | @NLocal id
@id=@WOpEq(@ParmS(1t)+" (chat)") @While @t<>"" @Skip (@Len(@t)>50)*3 @WAdd @id,@FGGreen+@t @t="" @Skip 2 @WAdd @id,@FGGreen+@Copy(@t,1,50) @t=@Copy(@t,51,255) @EndW |
These
pages were developed with Netscape Composer
4.03 by Alfredo Milani-Comparetti
Last modified on 8 nov 1997 |