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.

[SOLVED] Some questions

Help for those learning Tcl or writing their own scripts.
Post Reply
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

[SOLVED] Some questions

Post by Riddler »

Hy guys..

I have 2 question that I`m not sure about the answers... :?

How can I match a "lindex" split of the text following the public command with a handle and it's banlist to the eggdrop ?!

Ex:
(07:13) -> *|egg* banlist ryan
(07:13) -|egg- Handle ryan has 12 bans
ryan is [lindex [split $text] 0] in the syntax and also a handle to my eggdrop ... so how should I do it ?! ... this way:

Code: Select all

foreach bans [banlist $chan] {
  set author [lindex $bans 5]
  if {$author ==  [lindex [split $text] 0]} {
    puthelp "NOTICE $nick :Handle\002 $author  \002has $bans bans"
  } else {
    puthelp "NOTICE $nick :Handle\002 $author  \002has\002 NO \002 bans" 
  }
}

Is this corect :? :shock: :(
Last edited by Riddler on Sat Nov 28, 2009 8:12 pm, edited 1 time in total.
I am a man of few words, but many riddles
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: Question

Post by speechles »

Code: Select all

set bans_count 0
foreach bans [banlist $chan] {
    # can use -nocase option below if you wish case to be irrelevant
    if {[string equal -- [lindex [split $bans] 5] [lindex [split $text] 0]]} {
        set bans_count [expr $bans_count + 1]
    }
}
if {$bans_count > 0} {
    puthelp "NOTICE $nick :Handle \002[lindex [split $text] 0]\002 has $bans_count bans."
} else {
    puthelp "NOTICE $nick :Handle \002[lindex [split $text] 0]\002 has \002NO\002 bans."
}
unset bans_count
Without knowing what $bans is to really be doing, as in your code it's serving two purposes?? 1. holding contents of each iteration through the foreach or is it 2. used as a ban counter? It can't do both as your code suggests.
In the code I provided above, they are seperated and correctly handles strings and lists as what they really are. If you want more help than this, you need to better express your needs. :wink:

Edit: Haw, corrected the (obvious, thx metroid) bug regarding improper use of markers when setting variables. (set var != set $var.. my bad). :roll:
Last edited by speechles on Thu Mar 06, 2008 2:51 pm, edited 3 times in total.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Code: Select all

set count [llength [lsearch -all -exact -index 5 [banlist $chan] [lindex [split $text] 0]]]
('lsearch -all' requires tcl >= 8.4)
Have you ever read "The Manual"?
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Re: Question

Post by metroid »

speechles wrote:

Code: Select all

set $bans_count 0
foreach bans [banlist $chan] {
    # can use -nocase option below if you wish case to be irrelevant
    if {[string equal -- [lindex [split $bans] 5] [lindex [split $text] 0]]} {
        set $bans_count [expr $bans_count + 1]
    }
}
if {$bans_count > 0} {
    puthelp "NOTICE $nick :Handle \002[lindex [split $text] 0]\002 has $bans_count bans."
} else {
    puthelp "NOTICE $nick :Handle \002[lindex [split $text] 0]\002 has \002NO\002 bans."
}
unset $bans_count
Without knowing what $bans is to really be doing, as in your code it's serving two purposes?? 1. holding contents of each iteration through the foreach or is it 2. used as a ban counter? It can't do both as your code suggests.
In the code I provided above, they are seperated and correctly handles strings and lists as what they really are. If you want more help than this, you need to better express your needs. :wink:
You can't use "set $bans_count" like that.
Post Reply