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.

How to enclose "or" conditions into one condition?

Help for those learning Tcl or writing their own scripts.
Post Reply
d
daigo
Voice
Posts: 37
Joined: Fri Jun 27, 2014 8:02 pm

How to enclose "or" conditions into one condition?

Post by daigo »

This is the line I'm having trouble with:

Code: Select all

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.
w
willyw
Revered One
Posts: 1200
Joined: Thu Jan 15, 2009 12:55 am

Re: How to enclose "or" conditions into one condit

Post by willyw »

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.
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

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: Select all

if {[lindex [split $arg] 0] ne ""} {
if {[string match -nocase "*matchthis*" $arg]} {
would then become

Code: Select all

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.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Try it like this...

Code: Select all

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
.
d
daigo
Voice
Posts: 37
Joined: Fri Jun 27, 2014 8:02 pm

Post by daigo »

Oh, this works..I thought I tried this already, but I must've made a typo somewhere.
w
willyw
Revered One
Posts: 1200
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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. :)
Post Reply