| View previous topic :: View next topic |
| Author |
Message |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Sun Jul 27, 2014 6:51 am Post subject: How to enclose "or" conditions into one condition? |
|
|
This is the line I'm having trouble with:
| Code: | | if {[string match -nocase "abc" $txt] || [string match -nocase "def" $txt] || [string match -nocase "ghi" $txt] || [string match -nocase "jkl" $txt] && $nick eq "daigo"} |
Whenever someone says "abc" "def" or "ghi" the script responds to them, even though I stated that I want only the nickname "daigo" to be responded to. I assume this is because I need to enclose all 4 of the || conditions together, but I tried brackets [], {} and parentheses () but none of them work. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sun Jul 27, 2014 9:14 am Post subject: Re: How to enclose "or" conditions into one condit |
|
|
| daigo wrote: |
...
and parentheses () but none of them work.
|
I think parenthesis work.
Show us the line of code, exactly as you used it, that utilizes parenthesis. |
|
| Back to top |
|
 |
Get_A_Fix Master

Joined: 07 May 2005 Posts: 206 Location: New Zealand
|
Posted: Sun Jul 27, 2014 10:04 am Post subject: |
|
|
The parenthesis are necessary when you're using "".
For example, if I needed two conditions in an IF statement, ending in "", I would then use ( ) to keep it closed.
| Code: |
if {[lindex [split $arg] 0] ne ""} {
if {[string match -nocase "*matchthis*" $arg]} {
|
would then become
| Code: |
if {([lindex [split $arg] 0] ne "") && ([string match -nocase "*matchthis*" $arg])} {
|
This would fix your issue with the last condition of your statement; $nick eq "daigo" _________________ We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals. |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sun Jul 27, 2014 10:22 am Post subject: |
|
|
Try it like this... | Code: | | if {([string match -nocase "abc" $txt] || [string match -nocase "def" $txt] || [string match -nocase "ghi" $txt] || [string match -nocase "jkl" $txt]) && $nick eq "daigo"} |
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Sun Jul 27, 2014 11:01 am Post subject: |
|
|
| Oh, this works..I thought I tried this already, but I must've made a typo somewhere. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sun Jul 27, 2014 11:16 am Post subject: |
|
|
| daigo wrote: |
...
I thought I tried this already, but I must've made a typo somewhere.
|
That's why I asked for your exact code, as you used it.  |
|
| Back to top |
|
 |
|