Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Timer/Alarm for MUD script

Reply
Thread Tools

Timer/Alarm for MUD script

 
 
cstegmann@gmail.com
Guest
Posts: n/a
 
      05-20-2005
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

 
Reply With Quote
 
 
 
 
Christopher Nehren
Guest
Posts: n/a
 
      05-20-2005
On 2005-05-20, http://www.velocityreviews.com/forums/(E-Mail 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
--
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.
 
Reply With Quote
 
 
 
 
Mark Clements
Guest
Posts: n/a
 
      05-20-2005
(E-Mail Removed) 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
 
Reply With Quote
 
cstegmann@gmail.com
Guest
Posts: n/a
 
      05-21-2005
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.

 
Reply With Quote
 
Mark Clements
Guest
Posts: n/a
 
      05-21-2005
(E-Mail Removed) 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/arc...ntries/000300/

Mark
 
Reply With Quote
 
cstegmann@gmail.com
Guest
Posts: n/a
 
      05-21-2005
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";
}

 
Reply With Quote
 
Mark Clements
Guest
Posts: n/a
 
      05-21-2005
(E-Mail Removed) 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.ht...nstall_private
http://www.cpan.org/misc/cpan-faq.html

Mark

 
Reply With Quote
 
cstegmann@gmail.com
Guest
Posts: n/a
 
      05-22-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket MUD client script Zamnedix Python 2 10-30-2009 07:50 PM
Projecting MUD maps =?ISO-8859-1?Q?BJ=F6rn_Lindqvist?= Python 7 11-07-2006 04:24 AM
MUD Client and Python Plugin Framework Discipulus Python 1 05-23-2005 06:03 PM
mud(telnet) connection using Java Kevin Hsu Java 3 04-15-2004 09:17 PM
about the mud TheWater C++ 3 07-21-2003 03:49 PM



Advertisments