Timer/Alarm for MUD script

Discussion in 'Perl Misc' started by cstegmann@gmail.com, May 20, 2005.

  1. Guest

    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 {command}
    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
     
    , May 20, 2005
    #1
    1. Advertising

  2. On 2005-05-20, scribbled these
    curious markings:

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

    > 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 {command}
    > 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?


    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.
     
    Christopher Nehren, May 20, 2005
    #2
    1. Advertising

  3. wrote:

    > 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 {command}
    > 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.


    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.

    Mark
     
    Mark Clements, May 20, 2005
    #3
  4. Guest

    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.
     
    , May 21, 2005
    #4
  5. wrote:

    > 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.


    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
    script.

    Try

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

    Mark
     
    Mark Clements, May 21, 2005
    #5
  6. Guest

    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/i386-linux
    /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.6/i386-linux
    /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;

    POE::Kernel->run();

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

    sub part2 {
    print "Part 2\n";
    }
     
    , May 21, 2005
    #6
  7. wrote:

    > 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/i386-linux
    > /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl
    > /usr/lib/perl5/vendor_perl/5.8.6/i386-linux
    > /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;
    >

    <snip>
    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

    also

    http://www.cpan.org/misc/cpan-faq.html#How_install_private
    http://www.cpan.org/misc/cpan-faq.html

    Mark
     
    Mark Clements, May 21, 2005
    #7
  8. Guest

    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{confusion}) {
    $Concentrating = 1;
    print "concentrate\n";
    concereset;
    };
    };

    sub concentratingreset {
    $Concentrating=0;
    print "Concentrating has been reset\n";
    };

    sub concereset {
    POE::Session->create(
    inline_states => {
    _start => \&delaytime,
    event_part_two => \&concentratingreset,
    }
    );

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

    POE::Kernel->run();
    exit;
    };

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

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

    Any ideas?
    Thanks
     
    , May 22, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    761
    Kelsang Wangchuk
    Jul 31, 2003
  2. Replies:
    1
    Views:
    1,687
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  3. Alexnb
    Replies:
    0
    Views:
    274
    Alexnb
    Jun 13, 2008
  4. Zamnedix

    Socket MUD client script

    Zamnedix, Oct 30, 2009, in forum: Python
    Replies:
    2
    Views:
    445
    Terry Reedy
    Oct 30, 2009
  5. Ignoramus27279

    Timer/alarm clock module

    Ignoramus27279, Jul 29, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    209
    Tassilo v. Parseval
    Jul 30, 2005
Loading...

Share This Page