Topic: Scripting Misc

Topic: Scripting Misc

The topics covered here are some misc documentation which
is still valid. Most things are covered in the
"Scripting Basics" section, too.

Table 3.5. Subtopics

Looking for files Executing scripts Events

Looking for files

The @INC variable of the perl interpreter contains the
standard system includes as well as 
$KDEHOME/share/apps/xpertmud/perl and $KDEDIR/share/apps/xpertmud/perl.
$KDEDIR is the standard kde directory (usually /usr/ or /opt/kde2)
and $KDEHOME your personal kde directory (usally ~/.kde or ~/.kde2).
If you've got two scripts with the same name in both directories,
the one in your home directory will be found first. Of course you
can change @INC using the # directive or in your own scripts.
The standard scripts are a good place for learning the perl bindings,
so copy them to your home dir and change them to match your own requirements.


Executing scripts

If you want to test your scripts you probably don't want to reconnect
to the server everytime you changed something. To achive this you
can use the perl 'do' command. Perl will give quite a lot of warnings
when redefining functions, but the output will basically be what you
meant. For example, if you changed something within the bt3030.pl script
just type #do 'bt3030.pl' at the input line and the script will be
reloaded. If you care about parsing errors within your script
(which you probably do :) then there's a parse command that basically
tests the $@ variable after executing the do command and writing
an error message if there was something wrong. So the recommended
way to test your scripts is #parse 'bt3030.pl'.


Events

Everytime an event occurs a perl function is called. This is done
by a function reference which you can change to point to your
own piece of code. There are basically four events:

  - $onTimer gets no parameter and is called 4 times a second.
  - $onTextEntered gets the text entered at the input line and
    is called whenever enter is pressed. If you overwrite this, you have to
    implement evaluation of perl code for lines starting with # by yourself.
  - $onKeyPressed gets a string containing the currently
    pressed modifiers and the key's name as argument and is called everytime
    a key is pressed. Returns true if it reacted on the key, false otherwise.
  - $onTextReceived get a string containing a bunch of lines
    that came from the server. Ansi-Escape codes are still in there so
    be carefull with your regexps (espacially ^ can't be used if there's
    colored text at the beginning of the line). If you reimplement this,
    make sure that all interesting output will be written to some window.

You can overwrite one of the hooks simply by specifying
$onHook = sub { my $some = shift; blah blah ... };

Now all you have to know is how to generate windows and how
to put text into these windows before you can do anything you'll
ever want (hopefully :). 

See the help on the window classes.


KDE Logo