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.

Switch 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

Switch Help

Post by daltonc »

Hey, I am kinda new to the switch function, anyone wanna help? This isnt working..

Code: Select all

proc command:global {nick uhost hand chan arg} {
global botnick
if {[isop $nick #nrbots]} {
  switch [lindex $arg 1] {
    "rehash" {
     rehash
     if {[${botnick} == "nrbot-01"]} {
     putnotc $nick "Rehashing Complete"
     }
    }
    "cycle" {
     putserv "PART $chan :cycle"
     putserv "JOIN $chan"
   }
   default {
     putnotc $nick "Error(1): You didnt specify a global command."
   }
  }
 } else {
    putnotc $nick "Error(1): You lack access to the bot network"
    putnotc $nick "Error(2): Unable to 'global'"
  }
}
Its giving me.. the "You didnt specify a global 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:global {nick uhost hand chan arg} {
global botnick
    if {[isop $nick #nrbots]} {
        set command [lindex [split $arg] 1]
        
        switch -- $command {
            "rehash" {
                 rehash
                 if {$botnick == "nrbot-01"} {
                     putnotc $nick "Rehashing Complete"
                 }
            }
        
            "cycle" {
                putserv "PART $chan :cycle"
                putserv "JOIN $chan"
            }
       
            default {
                putnotc $nick "Error(1): You didnt specify a global command."
            }
        }
     
    } else {

        putnotc $nick "Error(1): You lack access to the bot network"
        putnotc $nick "Error(2): Unable to 'global'"
    }
}
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 »

Doesnt seem to work, when I do @global rehash. It gives me the error saying I didnt specify a command.
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

Change this

Code: Select all

set command [lindex [split $arg] 1]
To this

Code: Select all

set command [lindex [split $arg] 0]
$arg 1 would be the second element in the list after you called the proc so the first one which is what your matching it to should be 0 :wink:
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 »

Hey, thanks! It works now, got another question, how can I find out if there is a certin element in an array?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

daltonc wrote:Hey, thanks! It works now, got another question, how can I find out if there is a certin element in an array?
1st: this isnt an array, it's a list. arrays are used like: $array(element)
2nd: count the spaces or the {} expressions if present
example:
ex: 1 2 3 4 5
this has 5 elements

ex: {1 2} {3 4} 5
this has 3 elements

also remember, the first element has the index 0 ^-^.
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