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.

noobie help

Old posts that have not been replied to for several years.
Locked
d
daltonc
Voice
Posts: 29
Joined: Wed Apr 27, 2005 8:50 pm

noobie help

Post by daltonc »

if {[string tolower [lindex $arg 0]] !== "commands" || [string tolower [lindex $arg 0]] !== "website"} { , is that correct?

I get this error:

Tcl error [command:set]: syntax error in expression "[string tolower [lindex $arg 0]] !== "commands" || [string t"
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

In comparing:
== when matches
!= when doesn't match

It should be:

Code: Select all

if {([string tolower [lindex $arg 0]] != "commands") || ([string tolower [lindex $arg 0]] != "website")} {

Alternatively you can also use:

Code: Select all

if {![string equal -nocase "commands" [lindex $arg 0]] || ![string equal -nocase "website" [lindex $arg 0]]} {
Or just convert the string into string tolower and removed the -nocase option, like this:

Code: Select all

if {![string equal "commands" [string tolower [lindex $arg 0]]] || ![string equal -nocase "website" [string tolower [lindex $arg 0]]]} {
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
d
daltonc
Voice
Posts: 29
Joined: Wed Apr 27, 2005 8:50 pm

Post by daltonc »

Alright, thanks that seemed to get me through that error, here is my whole code:

Code: Select all

proc command:set {nick uhost hand chan arg} {

if {[isop $nick $chan]} {

if {[string tolower [lindex $arg 1]] == ""} {
putnotc $nick "Error(1): Nothing to set variable to."
} else {


if {[string tolower [lindex $arg 0]] == "commands" || [string tolower [lindex $arg 0]] == "roster" || [string tolower [lindex $arg 0]] == "website" || [string tolower [lindex $arg 0]] == "sponsors" || [string tolower [lindex $arg 0]] == "record"} {


  if {[string tolower [lindex $arg 0]] == "commands"} {
  set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
  putnotc $nick "Set commands to $commands"

 } elseif {[string tolower [lindex $arg 0]] == "roster"} {
  set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
  putnotc $nick "Set roster to $roster"

 } elseif {[string tolower [lindex $arg 0]] == "website"} {
  set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
  putnotc $nick "Set website to $website"

 } elseif {[string tolower [lindex $arg 0]] == "sponsors"} {
  set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
  putnotc $nick "Set sponsors to $sponsors"

 } elseif {[string tolower [lindex $arg 0]] == "record"} {
  set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
  putnotc $nick "Set record to $record"
 }


}
} else {
putnotc $nick "Error(1): Unable to set [string tolower [lindex $arg 0]], try using: commands,roster,website,sponsors,record"
} else {
putnotc $nick "Error(1): You lack access to the 'set' command."
putnotc $nick "Error(2): Unable to 'set' [string tolower [lindex $arg 0]]."
  }
 }
}
I am getting this error, I have done everything, moved brackets around and such. Anyone know:

Tcl error [command:set]: wrong # args: extra words after "else" clause in "if" command
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

Try this.

Code: Select all

proc command:set {nick uhost hand chan arg} {
    if {[isop $nick $chan]} {

        if {[string tolower [lindex $arg 1]] == ""} {
            putnotc $nick "Error(1): Nothing to set variable to."
            return
        }

        if {[string tolower [lindex $arg 0]] == "commands"} {
            set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
            putnotc $nick "Set commands to $commands"

        } elseif {[string tolower [lindex $arg 0]] == "roster"} {
            set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
            putnotc $nick "Set roster to $roster"

        } elseif {[string tolower [lindex $arg 0]] == "website"} {
            set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
            putnotc $nick "Set website to $website"

        } elseif {[string tolower [lindex $arg 0]] == "sponsors"} {
            set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
            putnotc $nick "Set sponsors to $sponsors"

        } elseif {[string tolower [lindex $arg 0]] == "record"} {
            set [string tolower [lindex $arg 0]] "[lrange $arg 1 end]"
            putnotc $nick "Set record to $record"

        } else {
        putnotc $nick "Error(1): Unable to set [string tolower [lindex $arg 0]], try using: commands,roster,website,sponsors,record"
        return
        }

    } else {
    putnotc $nick "Error(1): You lack access to the 'set' command."
    putnotc $nick "Error(2): Unable to 'set' [string tolower [lindex $arg 0]]."
    return
    }
}
I haven't tested this tho.

It also helps to properly format your code with the correct indentations to help see whats going on.

HTH.
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
d
daltonc
Voice
Posts: 29
Joined: Wed Apr 27, 2005 8:50 pm

Post by daltonc »

Great! That works, thanks dude! But for some strange reason its not picking up the variable in the next proc, here is what I have to read the commands variable

proc command:commands {nick uhost hand chan arg} {
putserv "NOTICE $nick :$commands"
}


In the channel I type @set commands @blah1 @blah2 , and then it goes putnotc $nick "I set your commands to $commands" therefore I know the variable is set yet when I type @commands to execute the proc commands:commands , it says its not set.

I am getting this error:
[10:52] Tcl error [command:commands]: can't read "commands": no such variable
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

daltonc wrote:proc command:commands {nick uhost hand chan arg} {
putserv "NOTICE $nick :$commands"
}
you forgot to global the variable. use

Code: Select all

proc command:commands {nick uhost hand chan arg} {
    global commands
    putserv "NOTICE $nick :$commands"
}
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

thats because you didnt make the variable global. I advise to use "set ::[.." to set and $::commands to read.
2 more suggestions:
use at the beginning

Code: Select all

        set arg [split $arg]
        set var [string tolower [lindex $arg 0]]
this saves you all the further tolower things, just use $var for the lindex thing and prevents the script from malefunctioning with "incorrect lists".

later for setting the var i would use that

Code: Select all

            set ::$var [join [lrange $arg 1 end]]
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Locked