| View previous topic :: View next topic |
| Author |
Message |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Wed Jun 28, 2006 4:10 pm Post subject: Question about an array |
|
|
Hello!
I have a question about an array. In one of my scripts I have this here:
| Code: | 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: |
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? |
|
| Back to top |
|
 |
krimson Halfop

Joined: 19 Apr 2006 Posts: 86
|
Posted: Wed Jun 28, 2006 4:27 pm Post subject: |
|
|
try using | Code: | foreach text [split $texts \n] {
if {[string match -nocase $text $reset]} {set case 1}
} |
it should work |
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Wed Jun 28, 2006 4:40 pm Post subject: |
|
|
| No, it doesn't. |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed Jun 28, 2006 7:20 pm Post subject: |
|
|
| Quote: | | set reset [lrange [split $arg] 0 2 |
You need to close the bracket.
| Code: | | set reset [lrange [split $arg] 0 2] |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Thu Jun 29, 2006 9:35 am Post subject: |
|
|
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: | 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. |
|
| Back to top |
|
 |
spock Master
Joined: 12 Dec 2002 Posts: 319
|
Posted: Thu Jun 29, 2006 10:29 am Post subject: |
|
|
try
| Code: | | if {[string match -nocase "Loading Level $map3" $reset]} |
and maybe | Code: | | set reset [join [lrange [split $arg] 0 2]] |
_________________ photon? |
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Thu Jun 29, 2006 10:49 am Post subject: |
|
|
| No, that doesn't work, too. |
|
| Back to top |
|
 |
spock Master
Joined: 12 Dec 2002 Posts: 319
|
Posted: Thu Jun 29, 2006 11:03 am Post subject: |
|
|
Yes, that does work, here.
edit: this works for me | Code: | 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? |
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Thu Jun 29, 2006 11:18 am Post subject: |
|
|
| OK, thank you, it works for me too now. |
|
| Back to top |
|
 |
|