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.

TCL error : Invalid timer ID

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

TCL error : Invalid timer ID

Post by z_one »

I got the following procedure that kills a given utimer.

Code: Select all

proc killthetimer {
global g_timerz

  if {[info exists g_timerz(timer:$l_uhost:$l_chan)]} {
    putlog "timer ID: $g_timerz(timer:$l_uhost:$l_chan)"
    killutimer $g_timerz(timer:$l_uhost:$l_chan)
    putlog "killed the timer"
  }
} 

When I run it I get the output timer ID: timer13424 then immediately after it I get TCL error: Invalid timer ID.
What's going on ? How can it not kill the utimer if its ID was correctly found ?
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

A simple Search would have saved a post.

Timers (Searching, killing, using time binds)
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

Post by z_one »

Yep I read this post.
But I also read in another post: http://forum.egghelp.org/viewtopic.php?p=74519 that you can use the [info exists timer] to directly determine if a timer is already running.

Code by "user".

Code: Select all

   if {[info exists timer]} { 
      killutimer $timer 
      unset timer 
   } 
Besides, Sir_Fz explains how to kill a timer when you know the proc it is linked to.
What if my timer is linked to something else like:

Code: Select all

set g_timerz(timer:$l_uhost:$l_chan) [utimer 4 "array unset g_linesperhost *$l_uhost*$l_chan*"]
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

1st: Don't mix timer and utimer..

2nd: "info exists timer" only checks wether the variable named "timer" exists or not. It does no check whatsoever wether the name within "timer" actually points to a valid timer or utimer.
As for the post made by "user", it depends on the proc preceding the example you posted, and expects the globalspace variable "timer" to hold the name of a speciffic timer. It also assumes that the code triggered by the timer will unset that very same variable.

3rd: In order to check wether a (u)timer actually exists, search the list generated by "timers" (or "utimers") for the existance of the actual timer. The link posted by Alchera illustrates how this is done.

4th: When creating a (u)timer, do it something like this:

Code: Select all

utimer 4 [list array unset g_linesperhost *$l_uhost*$l_chan*]
This way you don't have to worry about "special" characters and such. In case you wish to keep track of the timer-id, do something like this:

Code: Select all

set myvar [utimer 4 [list array unset g_linesperhost *$l_uhost*$l_chan*]]
NML_375
Post Reply