Timer/Alarm for MUD script

C

cstegmann

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
 
C

Christopher Nehren

On 2005-05-20, (e-mail address removed) 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
 
M

Mark Clements

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
 
C

cstegmann

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

Mark Clements

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
 
C

cstegmann

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";
}
 
M

Mark Clements

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
 
C

cstegmann

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top