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.

can't read "chan": no such variable ?

Help for those learning Tcl or writing their own scripts.
Post Reply
b
boehmi
Voice
Posts: 14
Joined: Sat Apr 11, 2009 7:55 am
Location: Germany

can't read "chan": no such variable ?

Post by boehmi »

Code: Select all

proc1 $chan
utimer 60 { proc2 $chan }
proc1 works correct... but the proc2-call within the {} throws the error can't read "chan": no such variable

Shouldn't $chan be valid inside a new {} block, just like in a do..while {} loop?

What is the problem?

Thanks for your help
F
Fill
Halfop
Posts: 80
Joined: Sun Jan 18, 2009 6:08 pm

Post by Fill »

nope, that's totally wrong. First of all, you can't write this:

Code: Select all

utimer 60 { proc 2 $chan }
Utimer commands are normally used inside brackets [], and if you want to execute a comand after 60 seconds (1 minute) you'll have to do something like this:

Code: Select all

utimer 60 [list proc2 $chan]
If you get no such variable with $chan, it's because you didn't load that variable on proc1. When is proc1 called?

Show me the whole script so I can understand better how we're going to load up $chan.
b
boehmi
Voice
Posts: 14
Joined: Sat Apr 11, 2009 7:55 am
Location: Germany

Post by boehmi »

erm no... proc2 is not a part of proc1
proc1 is just called 1 line before ;)

its for a little quizbot

Code: Select all

proc quiz_start { nick uhost hand chan args } {
        global quiz_status
        set quiz_status "started"
        sendmsg "PRIVMSG $chan :Quiz startet..."
         putlog "test"
         ask_question $chan
         utimer 60 [list give_answer $chan]
}

if i use utimer 60 [list proc2 $chan] he just does nothing :/
not even errors
Last edited by boehmi on Mon Apr 13, 2009 8:04 pm, edited 1 time in total.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Either there is no proc called give_answer, or the proc give_answer doesn't take a single argument (in this case $chan).
I must have had nothing to do
F
Fill
Halfop
Posts: 80
Joined: Sun Jan 18, 2009 6:08 pm

Post by Fill »

in that case you must have a proc like this:

Code: Select all

proc give_answer { chan } {
blah blah blah...
}
proc2 must take the chan argument as shown above. try it like that.

or...

if you don't want proc2 to have any arguments (proc2 {} { blah }), you can make $chan a global variable on proc1:

Code: Select all

proc1 { blah blah } {
global channel
set channel $chan
blah...
}
And then proc2 would be similar to this:

Code: Select all

proc2 {} { 
global channel
blah
}
b
boehmi
Voice
Posts: 14
Joined: Sat Apr 11, 2009 7:55 am
Location: Germany

Post by boehmi »

Fill wrote:in that case you must have a proc like this:

Code: Select all

proc give_answer { chan } {
blah blah blah...
}
proc2 must take the chan argument as shown above. try it like that.
yeah i did it like that... but the problem of my first post were the {} around the call.

However now it's working with [list ..]
Thank you very much
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

A word of advice for the future, avoid using "args" as an argument name. It'll "screw" things up for you if you are not aware of it's special properties.

If you'd like a more technical explanation how the timer/utimer command works, and why you should use the [list ...] approach, see this thread
NML_375
Post Reply