Re: Timer/Alarm for MUD script
- From: Christopher Nehren <apeiron+usenet@xxxxxxxxxxxxxxxxx>
- Date: 20 May 2005 13:55:54 GMT
On 2005-05-20, cstegmann@xxxxxxxxx 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.
.
- References:
- Timer/Alarm for MUD script
- From: cstegmann
- Timer/Alarm for MUD script
- Prev by Date: Timer/Alarm for MUD script
- Next by Date: Re: advocacy advice
- Previous by thread: Timer/Alarm for MUD script
- Next by thread: Re: Timer/Alarm for MUD script
- Index(es):
Relevant Pages
|