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.

problem with proc and global vars

Old posts that have not been replied to for several years.
Locked
Z
ZeleD
Voice
Posts: 11
Joined: Thu Nov 20, 2003 6:14 pm

problem with proc and global vars

Post by ZeleD »

This little test with timers give an error:

Tcl error in script for 'timer46':
can't read "looptimer": no such variable

Code: Select all

set trigger "0"
set looptimer "1"

if {![info exists timer_set]} {
 set timer_set [timer $looptimer "timer:action"]
}

proc timer:action {} {
  global looptimer
 putserv "sometxt"
 timer $looptimer timer:action
}

User avatar
TALES
Halfop
Posts: 59
Joined: Sun Nov 09, 2003 8:45 am
Location: Netherlands
Contact:

Post by TALES »

something like this??:

Code: Select all

set looptimer 1

if {![info exists {time-msg-loaded}]} {
 global time-msg-loaded looptimer
 set time-msg-loaded 1
 timer $looptimer timer:action
}

proc timer:action {chan} {
 global time-msg-loaded looptimer
 set time-msg-loaded 0
 putserv "PRIVMSG $chan :sometext"
 timer $looptimer timer:action
} 
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

TALES wrote:something like this??:

Code: Select all

set looptimer 1 

if {![info exists {time-msg-loaded}]} { 
 global time-msg-loaded looptimer 
 set time-msg-loaded 1 
 timer $looptimer timer:action 
} 
[snip]
This is not a proc, no need for the global line in it. Zeled's code looks fine, it should see the $looptimer.
Locked