Ungrouped Timers/Triggers/Etc

Posted by Xvordan on Fri 27 Jun 2014 06:24 PM — 4 posts, 18,485 views.

#0
I'm writing scripts for a mud I play, in which I make pretty judicious use of the DoAfter and DoAfterSpecial temporary timer creators. My problem is that, when I want to disable certain features, those temporary timers aren't, of course, automatically destroyed, and DeleteTimer/TimerGroup and its ilk won't let me use "" to referenced ungrouped or unlabled objects.

Is there anyway the Doafter and its similar DoAfterSpecial sibling could be made to support optional parameters after the duration and text to provide a label and a groupname? I know I could use AddTimer in place of DoAfter, but Doafter's just so convenient for temporary delays. Alternatively, is there a way to disable and/or delete such objects as have no group name or label?
Australia Forum Administrator #1
You can find the unlabelled triggers/timers etc. like this:


tl = GetTimerList ()
if tl then
  for k, v in ipairs (tl) do 
    Note (v) 
  end  -- for
end -- if we have any timers


That lists all timers, and uses an internal name for unlabelled ones, eg.


pilot_timer
*timer247   <--- this one is unlabelled
runaway


Knowing that, you can now use GetTimerInfo to find out things like their name and group, eg.


tl = GetTimerList ()
if tl then
  for k, v in ipairs (tl) do 
    print ("internal name =", v)
    print ("external name =", GetTimerInfo (v, 22) )
    print ("group =", GetTimerInfo (v, 19) )
    print ""
  end  -- for
end -- if we have any timers


Output:


internal name = pilot_timer
external name = pilot_timer
group = 

internal name = *timer247   <--- internal name
external name =             <--- this one is unlabelled
group = foo                 <--- this one is in a group

internal name = runaway
external name = runaway
group = 


Now you can just use that information to enable or delete them.
Amended on Fri 27 Jun 2014 08:42 PM by Nick Gammon
Australia Forum Administrator #2
Quote:

Is there anyway the Doafter and its similar DoAfterSpecial sibling could be made to support optional parameters after the duration and text to provide a label and a groupname?


You could do that yourself easily enough. Just write a function that looks similar to DoAfter which does what you want. After all, DoAfter is just a simplified interface to AddTimer with most parameters taking defaults.

Basically it adds a timer with:

  • Enabled = true
  • One-shot = true
  • Temporary = true
  • Active-when-closed = true
  • Send-to = as specified (eg. script, world, etc.)
  • At-time = "every x seconds" (not "at a time")
  • Time interval = as specified


You could write that in 5 minutes and call it MyDoAfter or something.
Australia Forum Administrator #3
Also see: http://gammon.com.au/modules

Scroll down to the addxml.lua part.

You can add timers, triggers and aliases easily by just setting up a Lua table and then calling addxml.trigger (t) (or timer or alias) as required.

This lets you set up the group easily.