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 

[solved] error regarding a variable

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


Joined: 18 Apr 2007
Posts: 7

PostPosted: Sat Apr 21, 2007 1:50 pm    Post subject: [solved] error regarding a variable Reply with quote

Hi all,

I get the following error message:
Code:
Tcl error [pub:command]: can't read "channels(output)": no such variable

when I type !command while i'm in channel #output, how can I solve this problem?

Thanks in advance!

Code:
set channels(output) "#output #output2"

set channels(output) [ split $channels(output) ]

bind pub -|- "!command" pub:command

proc pub:command { nick uhost hand chan args } {
  if { [ validchan $chan ] } {
    putquick "privmsg $chan :you called?"
  }
}

proc validchan { chan } {
  foreach c $channels(output) {
    if { $chan == $c } { return 1 }
    else { return 0 }
  }
}


Code:


Last edited by LethPhaos on Sun Apr 22, 2007 3:54 am; edited 2 times in total
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 21, 2007 2:12 pm    Post subject: Reply with quote

delete
Code:
proc validchan { chan } {
  foreach c $channels(output) {
    if { $chan == $c } { return 1 }
    else { return 0 }
  }
}

I don't see the use of this check (validchan) anyway, the bot is already on it when it saw the request.

Edit: After reading your post again, I noticed that the error you posted has nothing to do with the code you posted.

However, I suggest you change the name of your proc [validchan] since that is an Eggdrop Tcl command and may cause problems with other scripts.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
LethPhaos
Voice


Joined: 18 Apr 2007
Posts: 7

PostPosted: Sat Apr 21, 2007 2:22 pm    Post subject: Reply with quote

i'll change the name of the proc to checkchan
i'm not removing the proc because the bot doesn't have to react on the command on every channel it is in, only on channels specified in the var

what do you think is causing the problem?

thanks for your help!
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 21, 2007 2:38 pm    Post subject: Reply with quote

Quote:
Tcl error [pub:command]: can't read "prechan(output)": no such variable

In the code you've posted, there's no prechan array at all. I guess you've changed the names of the variables; your 'channels' array is not global in the validchan proc, so use $::channels(output) instead.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
LethPhaos
Voice


Joined: 18 Apr 2007
Posts: 7

PostPosted: Sat Apr 21, 2007 3:11 pm    Post subject: Reply with quote

oops, indeed forgot to replace one var name, fixed

edit: okay, it's workig now, due to your hint of adding the ::

but what does that do exactly? :p
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 21, 2007 7:37 pm    Post subject: Reply with quote

You want to use the global variable inside the procedure but you're using it as a local variable (belonging to the proc's level), using :: indicates that the variable is in the global namespace. You can add 'global channels' line in your proc and normally use $channels(output) instead.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
LethPhaos
Voice


Joined: 18 Apr 2007
Posts: 7

PostPosted: Sun Apr 22, 2007 3:53 am    Post subject: Reply with quote

Thanks a lot!
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