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.

Question about an array

Help for those learning Tcl or writing their own scripts.
Post Reply
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Question about an array

Post by darton »

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?
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

try using

Code: Select all

foreach text [split $texts \n] {
  if {[string match -nocase $text $reset]} {set case 1} 
}
it should work
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

No, it doesn't.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

set reset [lrange [split $arg] 0 2
You need to close the bracket.

Code: Select all

set reset [lrange [split $arg] 0 2]
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

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.
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

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?
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

No, that doesn't work, too.
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

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?
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

OK, thank you, it works for me too now.
Post Reply