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.

Several conditions ''&&" and '||' in one line

Help for those learning Tcl or writing their own scripts.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Several conditions ''&&" and '||' in one line

Post by juanamores »

I need each code segment separated by red brackets, is considered separately from other conditions.
if {(([lsearch -exact -ascii -nocase [lindex $text 0 end] [lindex $who1 0 end]] != -1) && ([llength [split $text]] == 2) \
&& ([string index $text end] == "$whof")) \
|| (([lsearch -exact -ascii -nocase [lindex $text 0 end] [lindex $who2 0 end]] != -1) && ([llength [split $text]] == 3) \
&& ([string index $text end] == "$whof")) \
|| (([lsearch -exact -ascii -nocase [lindex $text 0 end] [lindex $who3 0 end]] != -1) && ([llength [split $text]] == 4) && ([string index $text end] == "$whof")) != -1 } {
more stuff
}
I tried adding other brackets at the beginning of the code and at the end, but it is malfunctioning.
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

I see multiple possible reasons why this expression does not resolve as you might be wishing...
None of the reasons rest with the way you are grouping things together.

What exactly is in the variable $text ?
By its name, I have to expect it holds a text string, and not a list.
Sometimes you treat it as text, & others as a list with sublists?

1) In these parts of the expression, you treat $text as a nested list, sort of, and badly (these will probably never resolve to true)...

Code: Select all

([lsearch -exact -ascii -nocase [lindex $text 0 end] [lindex $who1 0 end]] != -1)
2) Right after that, you treat $text as a text string, properly splitting it into a list...

Code: Select all

([llength [split $text]] == 2)
3) And you finish off treating $text as a text string again...

Code: Select all

([string index $text end] == "$whof")
4) Then at the very end of your expression you just throw in an extra bit of code that has no home at all.
Even if the rest of that expression was correct, just throwing in extra operators here and there can't possibly help:)

Code: Select all

 != -1 } { 
In order for anyone to try to help with this mess, we would need much more information on what is included in the vars $text and $who1, 2 & 3.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Thanks to your advices SpiKe^^ I fixed!

My eternal confusion between string and list. :oops:

All variables were string!
I treated all variables as a text string, properly splitting it into a list, and deleted extra operators

Code: Select all

!= -1 } { 
I'll put the final solution at the right post. :D
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
Post Reply