This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Killtimers timerID...

Help for those learning Tcl or writing their own scripts.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Killtimers timerID...

Post by juanamores »

How to find the timerID from these examples?
1)

Code: Select all

utimer 120 [list putquick [encoding convertfrom utf-8 "PRIVMSG $chan :This is a quick message converted to UTF-8"]]
2)

Code: Select all

timer 3 [list putmsg $chan "Hello world"]
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: Killtimers timerID...

Post by willyw »

Play with this.
It is not meant for any actual use. It is just meant to illustrate.

Code: Select all

# May 26, 2015

# http://forum.egghelp.org/viewtopic.php?p=104159&sid=f40235b3e21a35b95678280c8ef33c3f#104159

### this finds only the first instance
bind pub - "!timers" search_timers

proc search_timers {nick uhost handle chan text} {

        putserv "privmsg $chan :timers are: [timers]"
        putserv "privmsg $chan :text is: $text"

        putserv "privmsg $chan :position in list of timers is: [lsearch -index 1 [timers] "*$text*" ] "

        set pos [lsearch -index 1 [timers] "*$text*" ]
        putserv "privmsg $chan :selected timer is: [lindex [timers] $pos]"
        set selected [lindex [timers] $pos]
        putserv "privmsg $chan :timer id is: [lindex $selected 2]"
}


###############
####  this will list all timers that match
bind pub - "!timersagain" find_all_timer_matches

proc find_all_timer_matches {nick uhost handle chan text} {

        putserv "privmsg $chan :timers are: [timers]"
        putserv "privmsg $chan :text is: $text"

        set pos "[lsearch -index 1 -all [timers] "*$text*" ]"
        putserv "privmsg $chan :selected timers are in these positions : $pos "

        foreach num $pos {
                putserv "privmsg $chan :timer is: [lindex [timers] $num]"
        }

        foreach num $pos {
                putserv "privmsg $chan :timerid is: [lindex [timers] $num 2]"
        }
}

Reference:
http://www.eggheads.org/support/egghtml ... mands.html
and
http://www.tcl.tk/man/tcl8.6/TclCmd/lindex.htm
and
http://www.tcl.tk/man/tcl8.6/TclCmd/lsearch.htm
You may wish to experiment with the -nocase switch.

I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Also, if you expect to need the timer id often, store it in a variable when you set the timer...

Code: Select all

set utimerid [utimer 120 [list putquick [encoding convertfrom utf-8 "PRIVMSG $chan :This is a quick message converted to UTF-8"]]]
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

SpiKe^^ wrote:Also, if you expect to need the timer id often, store it in a variable when you set the timer...

Code: Select all

set utimerid [utimer 120 [list putquick [encoding convertfrom utf-8 "PRIVMSG $chan :This is a quick message converted to UTF-8"]]]
Thanks to the contribution willyw.
I liked the idea of SpiKe^^ to keep the timerID in a variable, I tried it and it works perfect.
Thank you both. :D
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
Post Reply