egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to let an utimer know it`s own utimer id?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
sKy
Op


Joined: 14 Apr 2005
Posts: 194
Location: Germany

PostPosted: Wed Jul 18, 2007 1:26 pm    Post subject: How to let an utimer know it`s own utimer id? Reply with quote

Code:

proc lremove { list string } {
 return [lsearch -all -inline -not -exact $listname $string]
}


This sets the timers.
Code:

set timer 0
foreach element $list_of_ tasks {
 set timer [expr $timer + 5]
 set id [utimer $timer [list $element]]
 lappend ::list_with_timerids $id
}


This code is used in case of I want to kill the remaining utimers.
Code:

foreach id $::list_with_timerids {
 killutimer $id
}

The problem is that if the utimer has already been executed then it would throw an error invalid timerid. Sure I could use catch, but I don`t want to use catch.

I don`t want to use catch because some other utimer (set by another script) could have that id now and I could eventually kill the wrong timer because he has the same name.

The problem is set id [utimer $timer [list $element]]. I would like to expand the [list ...] section with a command to remove the utimer from $::list_with_timerids. With set :list_with_timerids [lremove $:list_with_timerids $id].

But this isn`t possible because I get the $id just after I did set the utimer. Is there some tricky work around?

As far I know I can not modify a timer/utimer/after after it has been set. Otherwise it would be easy.
_________________
socketapi | Code less, create more.
Back to top
View user's profile Send private message
sKy
Op


Joined: 14 Apr 2005
Posts: 194
Location: Germany

PostPosted: Fri Aug 24, 2007 6:32 pm    Post subject: Reply with quote

No one knows? No way? Or is my English to bad to understand what I want to do?
_________________
socketapi | Code less, create more.
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Fri Aug 24, 2007 7:45 pm    Post subject: Reply with quote

Timers (Searching, killing, using time binds)

The above helpful?
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Sat Aug 25, 2007 4:47 pm    Post subject: Reply with quote

There is no way to know the id at the time you create the code argument (because it doesn't exist yet).

If all the timers run for the same amount of time, your timer will always be the first on the list, which would let you use lrange to remove its id, but if the delay differs, that won't work...

I have the same problem with my socket api - code executed by the server socket needs to know its id, so I made my own "id" that is used to look up the real id. For timers it would be something like this:

Code:
array set myTimer {}
if {![info exists myTimerID]} {set myTimerID -1}

proc myTimer {delay code} {
   global myTimerID myTimer
   # The custom id is appended to your code and must be used to unset myTimer(theID) if you kill the timer
   set myTimer([incr myTimerID]) [utimer $delay [lappend code $myTimerID]]
   set myTimerID
}

proc killMyTimer id {
   upvar 0 ::myTimer($id) timer
   if {[info exists timer]} {
      killutimer $timer
      unset timer
   }
}


Use the concept in your script instead of using these procs to avoid adding overhead... or use "utimers" in your "kill remaining" code.
_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber