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.

Variables

Help for those learning Tcl or writing their own scripts.
Post Reply
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Variables

Post by garfwen »

removed
Last edited by garfwen on Thu Jun 28, 2012 2:19 am, edited 2 times in total.
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Post by garfwen »

ouh... the help texts are in Portuguese but I dont think its necessary to translate :\
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Simple, you create $forum and $site in global space. You may reference them as $forum and $site only when used in global space. If your using them within local space (inside of a procedure) you must add them as global variables in the global line, or reference them as $::forum and $::site.
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Post by garfwen »

Yeah !
It's working now.

Ty
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I do see a few flaws in your script. The first issue at hand is that you don't take variable-spaces into considderation. Variables created in globalspace generally cannot be accessed as local variables within a proc (except unless they've explicitly been linked to a local variable using upvar or global). Hence, you cannot use $globalvar within your proc to access the globalspace variable globalvar, use $::globalvar instead (or use the global command to link it to the localspace variable.

The second issue is that you named one of your parameters "args" in holm-join_greet raw:qauth. This name has a special meaning, and should be avoided unless you explicitly desire this behaviour ("args", when used as the last parameter in a proc declaration, may accept 0 or more arguments, concatenating them into a tcl-list).

Third issue is that you keep mixing lists and strings in a way that will cause your script to malfunction under certain conditions. Commands such as lindex expect a list, not a string, and will not operate correctly if the provided data is not a valid tcl-list structure.

This piece of code pretty much sums up all the above, and I'll add comments explaining the flaws and how to correct them..

Code: Select all

bind raw - 311 raw:qauth

#Proc has been declared with an "args" parameter, yet the raw binding always calls the proc with a fixed number of arguments.. Hence, args will be a tcl-list with one list-item containing all that the server sent us...
proc raw:qauth {from keyword args} {

 global Qauth Qpass Qhost

#Since args is a list, we have to use join to convert it into a string. Using a different parameter name would save us from this extra work...
 set args [string tolower [join $args]]

#But now, we've already converted args into a string, we can't use list operations on it, such as lindex...
#Even if we hadn't joined args into a string, you'd still have problems, as the initial list only had one list item containing the whole string, and all you'd end up with is having nick = "" and host = "@".
#What you need to do, is convert the string into a list. split usually does the trick here, and it also allows you to specify which character (default space) should be used to "split" upon.
 set nick [lindex $args 1]
 set host "[lindex $args 2]@[lindex $args 3]"

 if {$host == [string tolower $Qhost]} {
  puthelp "PRIVMSG Q@CServe.quakenet.org :AUTH $Qauth $Qpass"

#Here we try to read the local variable gatherbot, yet it has not been declared anywhere within the proc, thus this will throw an error and abort execution...
#Most likely, you were trying to access the globalspace variable with the same name. To do this, you'd either have to use the global command, or use a full path to the variable ($::gatherbot)
  puthelp "PRIVMSG $gatherbot :AUTH"
 }
}





### The proper code should look something like this instead:

bind raw - 311 raw:qauth
proc raw:qauth {from keyword text} {
 global Qauth Qpass Qhost
 set ltext [split $text]
 set nick [lindex $ltext 1]
 set host "[lindex $ltext 2]@[lindex $ltext 3]"

#I am using a slightly different way of comparing the hosts, saving me alot of case mangling.
 if {[string equal -nocase $host $Qhost]} {
  puthelp "PRIVMSG Q@CServe.quakenet.org :AUTH $Qauth $Qpass"
  puthelp "PRIVMSG $::gatherbot :AUTH"
 }
}
NML_375
Post Reply