| View previous topic :: View next topic |
| Author |
Message |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Fri May 15, 2015 10:59 pm Post subject: Several conditions ''&&" and '||' in one line |
|
|
I need each code segment separated by red brackets, is considered separately from other conditions.
| Quote: |
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  |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat May 16, 2015 12:48 am Post subject: |
|
|
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: | | ([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: | | ([llength [split $text]] == 2) |
3) And you finish off treating $text as a text string again... | Code: | | ([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:)
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
. |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sat May 16, 2015 1:44 am Post subject: |
|
|
Thanks to your advices SpiKe^^ I fixed!
My eternal confusion between string and list.
All variables were string!
I treated all variables as a text string, properly splitting it into a list, and deleted extra operators
I'll put the final solution at the right post.  _________________ 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  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|