egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Fri May 15, 2015 10:59 pm    Post subject: Several conditions ''&&" and '||' in one line Reply with quote

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 Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Sat May 16, 2015 12:48 am    Post subject: Reply with quote

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:)
Code:
 != -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
.
Back to top
View user's profile Send private message Visit poster's website
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Sat May 16, 2015 1:44 am    Post subject: Reply with quote

Thanks to your advices SpiKe^^ I fixed!

My eternal confusion between string and list. Embarassed

All variables were string!
I treated all variables as a text string, properly splitting it into a list, and deleted extra operators
Code:
!= -1 } {

I'll put the final solution at the right post. Very Happy
_________________
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 Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber