09-26-2017, 00:20 +0200
AuthorPost
CyBex  05-23-2005, 21:55   | [EGG] bind time Jabber  ICQ  AOL IM  Yahoo IM  MSN  Homepage
nie da
(Administrator)

Avatar

Member since 01/2004
260 Posts
Location: Berlin
bind time <flags> <mask> <procname>
proc <procname> <minutes> <hours> <day> <month> <year>

<flags> are not required, best use: -
<mask> is "MM HH dd mm yyyy" and can have wildcards (MM=minute, HH=hour, dd=day, mm=month(-1), yyyy=year)
<procname> a fucking nice name for your proc :)

The month comes with -1, januar is 00, december is 11

Examples:

bind time - * procname ; # is called every minute
bind time - "?5 *" procname ; # is called every 10 minutes, 05,15,25,35,45,55
bind time - "30 *" procname ; # is called every hour, 30 mins after full
bind time - "30 1? * 200?" procname ; # work from 10:30 - 19:30 every hour, but only in the year 2000-2009

proc procname {minute hour day month year} { .. } ; # full var support
proc procname {min hour args} { .. } ; # args is special var for a list
proc procname args { .. } ; # you dont need the time, only proc called

Hint:

To trim the minutes (or other vars) best use:
set minutes [string trimleft $minutes 0]; if {$minutes==""} {set minutes 0}

mfG CyBex @ QuakeNet, UnderNet, EFNet, Freenode, euIRC, GameSurge & ShadowWorld - Files
CyBex  12-05-2005, 05:17   | [EGG] (u)timer Jabber  ICQ  AOL IM  Yahoo IM  MSN  Homepage
nie da
(Administrator)

Avatar

Member since 01/2004
260 Posts
Location: Berlin
Syntax:
timer <min> <command>
utimer <sec> <command>

Description:
executes the given Tcl command after a certain number of minutes/seconds have passed

Return:
timerID

Something to Explain:
The <command> has no option, you need to create a list/string for this, when you need more then one word.

Examples:                                                                                                                               
1
2
3
4
timer 5 procname
# call procname after 5 mins when seconds are 00
utimer 30 procname
# call procname after 30 secs

List: Perfekt :)                                                                                                                               
1
2
3
4
utimer 60 [list command $arg1 $arg2]
# perfekt and easy way.. see next line :)
timer 1 [list putserv "PRIVMSG nick :$arg1"]
# no problems with Evaluation, no problems with vars...

Quotes: ATTENTION the timer evaluate the command before it get executed..
If you have [die] in your $argX you bot will die!                                                                                                                               
1
2
3
4
utimer 60 "comand $arg1 $arg2"
# you must escape something
timer 1 "putserv \"PRIVMSG nick :$arg1\""
# looks bad, but nick get the msg with the value of arg1 :)

Braces: Nothing get evaluated, you can not use vars and commands
Good for constant execution                                                                                                                               
1
2
3
4
utimer 60 {command $arg1 $arg2}
# command get \$arg1 and \$arg2 and not the value
timer 1 {putserv "PRIVMSG nick :$arg1}
  1. nick get a msg with $arg1 and not the value from the var

Save the timerID                                                                                                                               
1
2
set utimerID [utimer 300 something]
set timerID [timer 5 [list something with args]]



Syntax:
timers
utimer

Return:
a list of active minutely/secondly timers. Each entry in the list contains the number of minutes/seconds left till activation, the command that will be executed, and the timerID.

Something to Explain:
The return is a list in a list.. its like:
set timerlist [list [list timeleft1 command1 timerID1] [list timeleft2 command2 timerID2] .. [list timeleftN commandN timerIDN] ]

Examples:                                                                                                                               
1
2
3
4
5
6
7
8
foreach timer {[lsort -integer -index 0 -increasing [timers]} {
    # this is a trick to assign easy/fast list items to more then 1 var
    foreach {timeleft command timerID} $timer {break}
    # you can do also: set timeleft [lindex $timer 0]; set command [lindex $timer 1]; set timerID [lindex $timer 2]

    # now you can check/compare a timerid or a command..
    putlog "Timer $timerID will run in $timeleft minutes the command '$command'"
}


Other way to check the timers list:
                                                                                                                              
1
2
set found [expr {[lsearch [timers] *$myTimerIDvar]!=-1}]
# set 0/1 to found when timerID exists

                                                                                                                              
1
2
3
4
set position [lsearch [timers] *$myTimerIDvar]
# set the position in timerlist (or -1 when not found)
set timerID [lindex [timers] $position end]
# to get the timerID (or nothing if position is -1)

                                                                                                                              
1
2
set found [expr {[lsearch [timers] "*command arg1 arg2*"]!=-1}]
# set 0/1 when command is found

                                                                                                                              
1
2
set timerID [lindex [timers] [lsearch [timers] "*command arg1 arg2*"] end]
# get a timerID (or nothing) when command is found



Syntax:
killtimer <timerID>
killutimer <timerID>

Description:
removes a minutely/secondly timer from the list

Something to Explain:
Thats easy, you have learn before, how you can get the timerID of a specific timer. You need only to kill it, when you dont wanna evaluate the command.

Examples:                                                                                                                               
1
2
killtimer [lindex [timers] [lsearch [timers] "*command arg1 arg2*"] end]
# kill the timer with the command



More Infos:
Summary of Tcl language syntax, Eggdrop Tcl-Commands (Timers and more)

mfG CyBex @ QuakeNet, UnderNet, EFNet, Freenode, euIRC, GameSurge & ShadowWorld - Files
This post was edited 1 times, last on 07-23-2006, 10:21 by CyBex
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen