Timer/Alarm for MUD script

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi there,

i'm switching from windows to mandrake and have to give up on my zmud
system and craft an identical one in perl for kmuddy. I figured out how
to do most of my zmud coding in perl except for one thing: the #alarm
function in zmud.
THe syntax goes like this-> #alarm +3
This would wait for 3 seconds and then execute the command which could
be setting a certain variable or running a subroutine.

I read a little and only saw a lot of references to the sleep funtion.
But that halts the whole script and i'll be running this timer from in
a subroutine or a trigger and cannot have the rest of my system
disabled for that time.

Does anyone have any suggestions?

Thanks, Chris

Re: Timer/Alarm for MUD script

On 2005-05-20, cstegmann@gmail.com scribbled these
curious markings:

Being overly addicted to MUDs and online gaming, I feel obligated to
followup to this. :)

Quoted text here. Click to load it

What you'll want is Perl's built-in alarm function. It conveniently
takes a number of seconds as an argument. You'll need to set up a
handler for SIGALRM (see perlipc).

Unfortunately, you can only have one alarm running at a time. If you
want anything more complicated than that, you'll either need to keep
track of each applicable timer's countdown in the SIGALRM handler (which
would be kind of fun, actually...) and call alarm with the timeout for
the lowest countdown. Or you could use a prebuilt event-based framework,
like Event or POE.

<OT>Having a look at the project in which you'll be using this, I'm not
sure if using alarm will actually work. Do you know if kmuddy would
receive the signal, or if some external perl process would? If kmuddy
would, then it needs to propagate that signal to your script, or alarm
won't do you any good. You may find a better answer on
comp.unix.programmer or perhaps a KDE-specific mailing list.</OT>

Best Regards,
Christopher Nehren
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.

Re: Timer/Alarm for MUD script

cstegmann@gmail.com wrote:

Quoted text here. Click to load it

This might be overkill for what you are trying to do, but take a look
at POE. It is ideally suited to such problem domains.


Re: Timer/Alarm for MUD script

Thanks so much. I looked at POE and the delay() function looks just
like what i'm looking for. Now i just have to get it to work with EPIC
and ECLIPSE to be able to use it. I seemed to have installed it but i
can't get "use POE;" to work under EPIC, seems to read it as a compile
problem. But thanks a lot.

Re: Timer/Alarm for MUD script

cstegmann@gmail.com wrote:

Quoted text here. Click to load it

What error message do you get? Is possible that Epic's environment
isn't set up to see all your installed modules. I'm not familiar with
Epic, but generally you can fiddle with the PERL5LIB environment
variable, or there may be some use lib setting you can put in a startup


http://today.icantfocus.com/blog/archives/entries/000300 /


Re: Timer/Alarm for MUD script

The error message i get is this:

Can't locate POE.pm in @INC (@INC contains:
/usr/lib/perl5/5.8.6/i386-linux /usr/lib/perl5/5.8.6
/usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5
/usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3
/usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/perl5/vendor_perl/5.8.1
/usr/lib/perl5/vendor_perl .) at
/home/cstegmann/workspace/Achaea/MySystem/timers.pl line 3.
BEGIN failed--compilation aborted at
/home/cstegmann/workspace/Achaea/MySystem/timers.pl line 3.

The code/script is this:

use warnings;
use strict;
use POE;


sub part1 {
    print "Doing some work here...\n";
    $_[KERNEL]->delay( event_part_two => 5 );

sub part2 {
    print "Part 2\n";

Re: Timer/Alarm for MUD script

cstegmann@gmail.com wrote:

Quoted text here. Click to load it
OK - you have a choice. You either figure out how to tell Epic in which
directory you have installed POE (I have no idea how to do this beyond
trying to set PERL5LIB before you start it), or you can introduce a
line like this into your script:

use lib qw(/directory/where/I/have/installed/POE);

though clearly if you have more than one script then you wouldn't want
to include this line in each one and should find a better solution.

perldoc lib




Re: Timer/Alarm for MUD script

Thanks, i tried out a lot of stuff and finally got it to work. Now i
have a tiny problem with the POE itself. I've got this script here:

sub concentrate {
    if (!$Concentrating and !$afflictions) {
        $Concentrating = 1;
        print "concentrate\n";

sub concentratingreset {
    print "Concentrating has been reset\n";

sub concereset {
    inline_states => {
        _start         => \&delaytime,
        event_part_two => \&concentratingreset,

sub delaytime {
    $_[KERNEL]->delay( event_part_two => 2 );


but when i run concentrate; it waits for 2 seconds and then prints
Concentrating has been reset

I was trying to get
-2 second pause/delay
Concentrating has been reset.

Any ideas?

Site Timeline