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.
Help for those learning Tcl or writing their own scripts.
darton
Op
Posts: 155 Joined: Sat Jan 21, 2006 11:03 am
Post
by darton » Wed Jun 28, 2006 4:10 pm
Hello!
I have a question about an array. In one of my scripts I have this here:
Code: Select all
set reset [lrange [split $arg] 0 2]
if {[string match -nocase {text 1} $reset] || [string match -nocase {text 2} $reset]} {set case 1}
But now I want to replace the "text 1" and "text 2" with an array. So I made this:
Code: Select all
set case 0
set reset [lrange [split $arg] 0 2
set texts {
"text 1"
"text 2"
"text 3"
"text 4"
}
set texts2 {
"text 5"
"text 6"
"text 7"
}
foreach text $texts {
if {[string match -nocase $text $reset]} {set case 1}
}
foreach text2 $texts2 {
if {[string match -nocase $text2 $reset]} {set case 2}
}
But it don't set the variable "case" to 1 or 2. There must be something wrong with the foreach statements. Can anybody correct it for me?
krimson
Halfop
Posts: 86 Joined: Wed Apr 19, 2006 8:12 am
Post
by krimson » Wed Jun 28, 2006 4:27 pm
try using
Code: Select all
foreach text [split $texts \n] {
if {[string match -nocase $text $reset]} {set case 1}
}
it should work
darton
Op
Posts: 155 Joined: Sat Jan 21, 2006 11:03 am
Post
by darton » Wed Jun 28, 2006 4:40 pm
No, it doesn't.
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Wed Jun 28, 2006 7:20 pm
set reset [lrange [split $arg] 0 2
You need to close the bracket.
Code: Select all
set reset [lrange [split $arg] 0 2]
darton
Op
Posts: 155 Joined: Sat Jan 21, 2006 11:03 am
Post
by darton » Thu Jun 29, 2006 9:35 am
Of course I closed the bracket, but forgot to post it here. I give you now my whole script so that you can see what is wrong.
Code: Select all
bind pubm - * reset:flag
proc reset:flag {nick uhost hand chan arg} {
set reset [lrange [split $arg] 0 2]
set reset [stripcodes bcruag $reset]
set case 0
set 3er_maps {
"C&C_Under.mix"
"C&C_Hourglass.mix"
}
foreach map3 $3er_maps {
if {[string match -nocase {Loading Level $map3} $reset]} {set case 1}
}
if {$case == 1} {
putquick "PRIVMSG $chan :..."
}
If somebody in the channel writes "Loading level C&C_Under.mix" the variable "case" should be set to 1, but that does not happen.
spock
Master
Posts: 319 Joined: Thu Dec 12, 2002 8:40 pm
Post
by spock » Thu Jun 29, 2006 10:29 am
try
Code: Select all
if {[string match -nocase "Loading Level $map3" $reset]}
and maybe
Code: Select all
set reset [join [lrange [split $arg] 0 2]]
photon?
darton
Op
Posts: 155 Joined: Sat Jan 21, 2006 11:03 am
Post
by darton » Thu Jun 29, 2006 10:49 am
No, that doesn't work, too.
spock
Master
Posts: 319 Joined: Thu Dec 12, 2002 8:40 pm
Post
by spock » Thu Jun 29, 2006 11:03 am
Yes, that does work, here.
edit: this works for me
Code: Select all
bind pubm - * reset:flag
proc reset:flag {nick uhost hand chan arg} {
set reset [join [lrange [split $arg] 0 2]]
# set reset [stripcodes bcruag $reset]
set case 0
set 3er_maps {
"C&C_Under.mix"
"C&C_Hourglass.mix"
}
foreach map3 $3er_maps {
if {[string match -nocase "Loading Level $map3" $reset]} {set case 1}
}
if {$case == 1} {
putquick "PRIVMSG $chan :..."
}
}
photon?
darton
Op
Posts: 155 Joined: Sat Jan 21, 2006 11:03 am
Post
by darton » Thu Jun 29, 2006 11:18 am
OK, thank you, it works for me too now.