![]() TCL |
Eggdrop TCL Scripts in General A TCL script is created as an ordinary text file. Hence, appropriate programs to use in editing such a script would include Notepad (in Windows) and pico (in Linux). The main eggdrop configuration file (usually named eggdrop.conf) is an example of a TCL script. Indeed, that file must be edited in order to add any other scripts to a bot. Let's take a look at how that is done:
source testing.tcl That's
all there is to it. When the bot is started
up in the shell, the main configuration file
will do whatever it normally did, and it will
also load and execute the script named testing.tcl.
It is quite likely that the main configuration file already has several statements in it that begin with the word source. Naturally, they also load and run scripts. It is even possible to have a script that is loaded this way to contain source commands of its own, which will in turn load still more scripts. ExerciseLook
at the contents of your bot's main configuration
file, find all the source commands in
it, and list the names of the script files loaded
that way. Then go to each of those files, and
repeat the process. You should end up with a
(fairly lengthy) list of all the TCL scripts
that your bot is already running.
What TCL Scripts Look LikeEvery
TCL file consists of a bunch of TCL commands,
listed one after another. Nothing else can
be in the file. The simplest arrangement is
simply one command per line; in fact, the
rule of thumb is that a command's end is indicated
by the end of the line being reached Here
is an example of that arrangement:
set horrible 42 In that example, there
are four commands in the script: two set
commands, a putlog command, and a source
command. Notice that:
set horrible 42; set wonderful 16That example has five commands: two set commands, a putlog command, a # command, and a source command, with 2, 2, 1, 5, and 1 arguments, respectively. Finally,
a command can go beyond one line, ending the
first line of it with an open brace: { bind pubm - moron saidmoron In
that example, there are two commands, namely
bind and proc. The bind
has four arguments, whereas the proc
has only three. Notice how braces {} have
been used to group five things together into
the second argument of the proc command,
and braces have been used again to group together
a lot of things into the third argument. Moreover,
the opening brace of that third argument ends
the first line of the proc command.
Now, the proc command expects its third
argument to be a bunch of TCL commands --
essentially a whole TCL script. Let's look
again at that third argument:
if { $nick == "Pulse" } { This third argument turns
out in this case to consist of ONE command,
namely an if command. That command
has four arguments, of which only the third,
namely else, is not enclosed in braces.
All of the above may seem rather trite at first glance. But it is CRUCIAL to think always if the code you write is consistent with the ideas discussed above. As a prime example of how crucial this is, consider that last example, where we discussed the third argument of the proc command. Suppose we had written it as follows: if { $nick == "Pulse" } { Doing
it that way, we no longer have one if
command with four arguments. Instead, we would
have one if command with two arguments,
and one else command with one argument.
Since there is no such thing as an else
command in TCL, that last version would produce
an error, and the script would not work.
ExerciseConsider
the following TCL script:
For the above script:
Answers
|
|