How to remove all timers, or remove one timer.

Posted by Jlake on Mon 01 Apr 2002 11:54 AM — 3 posts, 15,092 views.

#0
After addtimer,I want to remove it after some time.
How to do this?
Australia Forum Administrator #1
There are a few ways you can do this. You haven't said how you would define "after some time" but I'll give various methods ...

  1. The simplest is to make a one-shot timer. This will fire once and then delete itself. This is handy if you only want to do something once, but in the future (eg. in 5 minutes).

  2. Next, you could make two timers, one which deletes the second one, like this:


    World.addtimer "my_timer", 0, 0, 20, "drink water", 1, ""
    World.addtimer "delete_my_timer", 0, 5, 0, "", 5, "delete_timer"


    The first timer (my_timer) fires every 20 seconds, and sends "drink water" to the MUD.

    The second timer (delete_my_timer) fires after 5 minutes, and is a one-shot timer (hence the flag of 5). It calls a script delete_timer.

    The script delete_timer would look like this:


    sub delete_timer (timer_name)
    world.deletetimer "my_timer"
    end sub



  3. You could use a trigger or alias to delete the timer. A trigger might be used if you wanted to do it automatically when something happened, an alias if you wanted to do it yourself.

    In each case they would call a script like this:


    sub OnDeleteTimer (strName, strLine, aryWildcards)
    world.deletetimer "my_timer"
    end sub


  4. If you have lots of such timers it gets slightly more complicated because then you need a way of knowing which timer to delete. I would then use a variable to remember which timer to delete.
#2
Thanks a lot.